题目大意: 给你一个蛋糕(半径为100) 上面有2N个草莓
你的任务是找出一条直线(Ax+By=0)均分这个蛋糕,要求大小相等,草莓数各为N;
输出A B
1. ax+by>0 点在直线上方
ax+by=0 点过直线
ax+by<0 点在直线下方
2.-500<=A B<=500 枚举就好 注意不要超时
#include<algorithm>
#include<stdio.h>
#include<iostream>
using namespace std;
int con[50][50];
int n;
bool judge(int a, int b){
int up = 0, down = 0;
for (int i = 0; i < 2 * n; i++){
int m = con[i][0] * a + con[i][1] * b;
if (m == 0)
return false;
else if (m>0)
up++;
else
down++;
}
if (up != down)
return false;
else
return true;
}
void solve(){
int a, b;
for (a = -500; a <= 500; a++){
for (b = -500; b <= 500; b++){
if (!judge(a, b))
continue;
else {
printf("%d %d\n", a, b);
return ;
}
}
}
}
int main(){
while (scanf_s("%d", &n) ==1 && n){
for (int i = 0; i < 2 * n; i++){
scanf_s("%d%d", &con[i][0], &con[i][1]);
}
if (judge(0, 1)){
cout << "0 1" << endl;
continue;
}
solve();
}
return 0;
}