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) { 7 int pos = 0, neg = 0; 8 for (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 else 15 return false; 16 } 17 18 return (pos == neg); 19 } 20 21 int main(int argc, char *argv[]){ 22 int N; 23 int cherries[MAXELE][2]; 24 25 while (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 } 45 return 0; 46 }
这里的东西都是自娱自乐的.我只是抱着构思算法的心态去做UVA的题.
我所有的code都不可能AC的.因为我就没想着让它能AC.


浙公网安备 33010602011771号