题意:生日蛋糕上面有2N草莓,怎么切能够将蛋糕和草莓平分成俩份,直接枚举,A和B,草莓不能落在直线上
#include#include #include using namespace std;#define null NULLint N = 110;int f(int a, int b, int x, int y){ return a * x + b * y;}int main(int argc, char* argv[]){ //freopen("C:\\Users\\zzzzz\\Desktop\\1.txt", "r", stdin); int n; int x[N]; int y[N]; while (cin >> n) { if (n == 0) return 0; for (int i = 0; i < 2 * n; i++) cin >> x[i] >> y[i]; int ok = 1; for (int a = -500; a <= 500 && ok; a++) { for (int b = -500; b <= 500 && ok; b++) { int l = 0, r = 0; for (int i = 0; i < 2 * n; i++) { int k = f(a, b, x[i], y[i]); if (k == 0) break; if (k < 0) l++; else r++; } if (l == n && r == n) { cout << a << " " << b << endl; ok = 0; } } } } return 0;}
posted on 2017-10-15 18:12 阅读( ...) 评论( ...)