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

为什么超时呢?help!!!!!!!!!

Posted by onandon at 2007-12-02 16:09:16 on Problem 3467
#include<stdio.h>
int n,m;
int times;
int count;
int main()
{
	int k,h,i,j,c,q,a[101][101];
	char ch;
	while(scanf("%d%d%d%d",&n,&m,&c,&q)!=EOF)
	{
		for(i=1;i<=n;i++)
			for(j=1;j<=n;j++)
				scanf("%d",&a[i][j]);
		for(h=0;h<q;h++)
		{
			scanf("%c",&ch);
			if(ch=='C')
			{
				scanf("%d%d%d",&i,&j,&k);
				a[i][j]=k;
			}
			else if(ch=='Q')
			{
				scanf("%d",&k);
				if(k>c)
					printf("%c\n",'0');
				else
				{
					int i,j,d;
					count=0;
					for(i=2;i<n;i++)
						for(j=2;j<m;j++)
						{
							if((a[i][j]==a[i][j-1])&&(a[i][j]==a[i][j+1])&&
							(a[i][j]==a[i-1][j])&&(a[i][j]==a[i+1][j])&&(a[i][j]==k))
							{
				
								count++;
								if(i>=3&&j>=3&&i+2<=n&&j+2<=m)
								{
									times=1;
									while(1)
									{
										times++;
										if((i+times)>m||(j+times)>n||(i-times)<1||(j-times)<1)
												break;
										else if((a[i+times][j]==k)&&(a[i-times][j]==k)&&
												(a[i][j+times])&&(a[i][j-times]))
											count++;
										else break;
									}
								}
							}
							else if(a[i][j+1]!=k)
								j++;
						}
						printf("%d\n",count);
				}
			}
		}
	}
	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