#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>// #define INPUT/** Problem: UVA10167 - Birthday Cake Begin Time:22nd/Mar/2012 5:00 p.m. End Time: 22nd/Mar/2012 7:35 p.m. Last Time: 2H 35M Thought: 就是根據題目中給的條件搜尋 1.A,B∈[-500,500] 2.至少有一個解,輸出其中之一就可以了 Experience: 這麼簡單的一道題,竟然WA了10次+,究其原因,就是審題不細 + 搜尋功底不行 1.由於審題不細,有2n lines follow沒看到,導致輸入的時候只輸入了N行,WAWAWA 2.由於審題不細,沒看到給出了答案的範圍,從而想得有些複雜,WAWAWA 3.搜尋的時候一定要注意!!先搜尋再判斷解,在這道題裡是這樣的 如果你把判斷解先放在前面,那麼可能搜尋到了下一個狀態,但是你的解停留在 上一個狀態,這時候你輸出的i,j是現在的狀態而不是上一個狀態,導致WA,這個 問題是WA的最多次的,日日日。 Knowledge Point: 單純的搜尋,甚至歸類不能歸成BFS/DFS。*/using namespace std;const int MAX_CHERRY = 110000;struct node{ int x; int y;};node cherry[MAX_CHERRY];void Solve(const int num){ int moreThan = 0; int lessThan = 0; for(int i = -500 ; i <= 500 ; i++) { for(int j = -500 ; j <= 500 ; j++) { moreThan = 0; lessThan = 0; for(int k = 0 ; k < num ; k++) { if(cherry[k].x * i + cherry[k].y * j > 0) { moreThan++; } if(cherry[k].x * i + cherry[k].y * j < 0 ) { lessThan++; } if(cherry[k].x * i + cherry[k].y * j == 0) { break; } if(moreThan == lessThan && moreThan + lessThan == num) { printf("%d %d\n",i,j); return; } } } }}int main(){#ifdef INPUT freopen("b:\\acm\\uva\\UVA10167\\input.txt","r",stdin);#endif int n; int x,y,num; while (scanf("%d",&n) != EOF ) { if ( n == 0 ) break; x = 0 ; y = 0 ; num = 0; for(int i = 0 ; i < 2 * n ; i++) { scanf("%d %d",&cherry[i].x,&cherry[i].y); } Solve(2*n); } return 0;}