Advertisement
juanjo12x

UVA_141_The_Spot_Game

Aug 2nd, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.16 KB | None | 0 0
  1. #include<cstdio>  
  2. #include<cstdlib>  
  3.  
  4. #define N 52  
  5.  
  6. using namespace std;  
  7.  
  8. typedef struct _Spot{  
  9.     bool chess[N][N];  
  10. }Spot;  
  11.  
  12. Spot spot[8*N];  
  13. bool game[N][N];  
  14. int n;  
  15.  
  16. int Init()  
  17. {  
  18.     for(int i = 0;i < n;++i)  
  19.         for(int j = 0;j < n;j++)  
  20.         {  
  21.             game[i][j] = false;  
  22.         }  
  23.  
  24. }  
  25.  
  26. int  Add_spot(int num)  
  27. {  
  28.     for(int i = 0;i < n;i++)  
  29.         for(int j = 0;j < n;j++)  
  30.             spot[num].chess[i][j] = game[i][j];  
  31.     num++;  
  32.     for(int i = 0;i < n;i++)  
  33.         for(int j = 0;j < n;j++)  
  34.             spot[num].chess[i][j] = game[n-j][i];  
  35.     num++;  
  36.     for(int i = 0;i < n;i++)  
  37.         for(int j = 0;j < n;j++)  
  38.             spot[num].chess[i][j] = game[n-i][n-j];  
  39.     num++;  
  40.     for(int i = 0;i < n;i++)  
  41.         for(int j = 0;j < n;j++)  
  42.             spot[num].chess[i][j] = game[j][n-i];  
  43. }  
  44.  
  45. bool judge(int num)  
  46. {  
  47.     for(int i = 0;i < n;i++)  
  48.         for(int j = 0;j < n;j++)  
  49.             if(game[i][j] != spot[num].chess[i][j])  
  50.                 return false;  
  51.     return true;  
  52. }  
  53.  
  54. int main()  
  55. {  
  56.     while(~scanf("%d",&n) && n)  
  57.     {  
  58.         Init();  
  59.         int result = 0;  
  60.         int cc = 0;  
  61.         for(int i = 1;i <= 2*n;++i)  
  62.         {  
  63.             int xx,yy;  
  64.             char oper;  
  65.             scanf("%d %d %c",&xx,&yy,&oper);  
  66.             game[xx-1][yy-1] = '+' == oper ? true : false;  
  67.  
  68.             if(!result)  
  69.             {  
  70.  
  71.                 bool check = false;  
  72.                 for(int p = 0;p < cc;p++)  
  73.                     if(judge(p))  
  74.                     {  
  75.                         check = true;  
  76.                         break;  
  77.                     }  
  78.                 if(check)  
  79.                     result = i%2==0 ? -i:i;  
  80.                 Add_spot(cc);  
  81.                 cc+=4;  
  82.             }  
  83.         }  
  84.         if(result > 0)  
  85.             printf("Player 2 wins on move %d\n",result);  
  86.         else if(result < 0)  
  87.             printf("Player 1 wins on move %d\n",-result);  
  88.         else  
  89.             printf("Draw\n");  
  90.     }  
  91.     return 0;  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement