| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
代码有注释,请高手看看哪里有问题#include <iostream>
using namespace std;
const int MAX = 20;
struct node
{
int winner;
int x,y;
node(){winner=0,x=0,y=0;};
};
int C,i,j,k;
int map[MAX][MAX];
//八个方向
int direction[8][2] = {{0,-1},{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1}};
//确定哪个方向满足条件后,定位到满足条件的点;
int rs[8][2] = {{0,-4},{-4,-4},{-4,0},{0,0},{0,0},{0,0},{0,0},{4,-4}};
node* test(int x,int y)
{
int tempx = x;
int tempy = y;
for(k=0;k<8;k++)
{
int count = 0;
while(tempx+direction[k][0] > 0 && tempx+direction[k][0] < 20 && tempy+direction[k][1] > 0 && tempy+direction[k][1] < 20 && map[tempx+direction[k][0]][tempy+direction[k][1]] == map[x][y])
{
count++;
tempx += direction[k][0];
tempy += direction[k][1];
}
if(count == 4)
{
if(x-direction[k][0] > 0 && x-direction[k][0] < 20 && y-direction[k][1] > 0 && y-direction[k][1] < 20 && map[x-direction[k][0]][y-direction[k][1]] == map[x][y])
return NULL;
node* temp = new node();
temp->winner = map[x][y];
temp->x = x+rs[k][0];
temp->y = y+rs[k][1];
return temp;
}
}
return NULL;
}
int main()
{
scanf("%d",&C);
while(C)
{
node* result = new node();
node* t = NULL;
for(i=1;i<MAX;i++)
{
for(j=1;j<MAX;j++)
scanf("%d",&map[i][j]);
}
for(i=1;i<MAX;i++)
{
for(j=1;j<MAX;j++)
{
if(map[i][j])
{
t = test(i,j);
if(t != NULL)
break;
}
}
if(t != NULL)
break;
}
if(t != NULL)
result = t;
printf("%d\n%d %d\n",result->winner,result->x,result->y);
C--;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator