Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:求帮忙检测错误啊,我崩溃了,之前那个的小错误改了,但还是错

Posted by Rage_H at 2011-08-09 19:06:48 on Problem 3546
In Reply To:求帮忙检测错误啊,我崩溃了 Posted by:Rage_H at 2011-08-09 17:35:22
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<iostream>
char matrix[15][15];
int vis[15][15];
const int dx[]={0,1,1,1};
const int dy[]={1,-1,0,1};
int ship[5]={0,4,3,2,1};
int dis;
int search(int i,int j,int dir)
{
	int nx,ny,ll,k,tx,ty;
	nx=i+dx[dir];ny=j+dy[dir];//	printf("%d,%d--->%d,%d\n",i,j,nx,ny);
	if(matrix[nx][ny]=='1')
	{
		if(vis[nx][ny])
			return -1;
		else
		{
			dis++;
		
			ll=search(nx,ny,dir);
			if(ll<0)
				return -1;
			else
			{
				vis[i][j]=2;
			//	printf("%d,%dbecome 2\n",i,j);
				for(k=0;k<4;k++)
				{
					tx=i+dx[k];ty=j+dy[k];
					if(vis[tx][ty]!=2)
					{
			//			printf("%d,%dbecome 1\n",tx,ty);	
						vis[tx][ty]=1;
					
					}
				}
				return 0;
			}
		}
	}
    vis[i][j]=2;
//	printf("%d,%dbecome 2\n",i,j);
	for(k=0;k<4;k++)
	{
		tx=i+dx[k];ty=j+dy[k];
		if(vis[tx][ty]!=2)
		{
		//	printf("%d,%dbecome 1\n",tx,ty);		
			vis[tx][ty]=1;
		}
	}
	return 0;
}


int main()
{
	int i,j,k,nx,ny,flag,tx,ty;
	freopen("text.txt","r",stdin);
	memset(matrix,'0',sizeof(matrix));
	memset(vis,0,sizeof(vis));
	for(i=1;i<=10;i++)
		gets(matrix[i]+1);
	for(i=1;i<=10;i++)
	{
		if(matrix[1][i]=='1'||matrix[i][1]=='1'||matrix[10][i]=='1'||matrix[i][10]=='1')
		{
			printf("incorrect\n");
			return 0;
		}
	}
	for(i=2;i<=9;i++)
	{
		for(j=2;j<=9;j++)
		{
			if(matrix[i][j]=='1')
			{
			//	printf("(%d,%d)vis:%d\n",j,i,vis[i][j]);
				if(!vis[i][j])
				{
					flag=0;
					for(k=0;k<4;k++)
					{
						nx=i+dx[k];ny=j+dy[k];	
						if(matrix[nx][ny]=='1')
						{
					    //	printf("===%d,%d--->%d,%d===\n",i,j,nx,ny);
							flag=1;
							dis=1;
						
							if(search(i,j,k)==0)
							{
						
								if(dis>4)
								{
									printf("incorrect\n");
									return 0;
								}	
								//printf("%d\n",dis);
						//		printf("begin:(%d,%d),direction:%d,distance:%d\n",i,j,k,dis);
							//	printf("---deal\n");
							
								ship[dis]--;
							
								//break;
							}
							else
							{
					//			printf("incorrect point:%d,%d",nx,ny);
								printf("incorrect\n");
								return 0;
							}
						}
					}
					if(!flag)
					{
						
					//	printf("begin:(%d,%d),,,,vis:%d\n",i,j,vis[i][j]);
						ship[1]--;
						vis[i][j]=2;
						for(k=0;k<4;k++)
						{
							tx=i+dx[k];ty=j+dy[k];
					        vis[tx][ty]=1;
						}
					}
				}
				else
				{
					if(vis[i][j]==1)
					{
					//	printf("incorrect point:%d,%d",i,j);
						printf("incorrect\n");
						return 0;
					}
				}
			}
		}
	}
//	printf("pass\n");
//	printf("%d %d %d %d\n",ship[1],ship[2],ship[3],ship[4]);
	if(!ship[1]&&!ship[2]&&!ship[3]&&!ship[4])
		printf("correct\n");
	else
		printf("incorrect\n");
		
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator