700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > UVA 10167 - Birthday Cake

UVA 10167 - Birthday Cake

时间:2020-03-05 11:25:32

相关推荐

UVA 10167 - Birthday Cake

这个就是一道很简单的枚举法的题目.

枚举A和B从-500到500的所有值(A==0 && B==0)除外

View Code

1 #include <iostream> 2 using namespace std; 3 4 const int MAXELE = 50; 5 6 bool FairCut(int a, int b, int cherries[][2], int N) { 7int pos = 0, neg = 0; 8for (int i = 0; i < 2*N; i++){ 9 int result = cherries[i][0]*a + cherries[i][1]*b;10 if (result > 0)11 pos++;12 else if (result < 0)13 neg++;14 else15 return false;16}17 18return (pos == neg);19 }20 21 int main(int argc, char *argv[]){22int N;23int cherries[MAXELE][2];24 25while (cin >> N && N != 0){26 for (int i = 0; i < MAXELE; i++)27 for (int j = 0; j < 2; j++)28 cherries[i][j] = 0;29 30 for (int i = 0; i < 2*N; i++)31 cin >> cherries[i][0] >> cherries[i][1];32 33 int a, b;34 bool found = false;35 for (a = -500; a <= 500 && !found; a++){36 for (b = -500; b <= 500 && !found; b++){37 if (a == 0 && b == 0)38 continue;39 found = FairCut(a, b, cherries, N);40 }41 }42 if (found)43 cout << a << " " << b << endl;44}45return 0;46 }

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。