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

求救 : 为什么是Time Limit Exceeded??

Posted by huojian at 2011-04-29 13:29:06 on Problem 2777 and last updated at 2011-04-29 13:31:40
# include <stdio.h>
# include<string.h>
# include<stdlib.h>

int a[100001];
void paint(int x,int y,int k)
{
	int i;
	if (x>y) { i=x;x=y;y=i;};
	for (i=x;i<=y;i++)
	a[i]=k;
};
long  count(int x,int y)
{
	int find[31];
	
	memset(find,0,sizeof(find));
	
	long  i,tot=0;
	if (x>y) { i=x;x=y;y=i;};
	for (i=x;i<=y;i++)
		if(! find[a[i]]) {
			tot++;
			find[a[i]]=1;
		}
	return tot;
}	
int main()
{
	long t;
	char c;
	long  i,j,k;
	long L,K;

	char s[10];
	scanf("%ld %ld %ld\n",&L,&K,&t);
	memset(a,0,sizeof(a));
//for (i=0;i<L;i++) a[i]=1;
	while (t--){
		scanf("%c",&c);
		if(c=='C') {
			scanf("%ld %ld %ld\n",&i,&j,&k);
			paint(i,j,k-1);
				
			}
		else {
			scanf("%ld %ld\n",&i,&j);
		    printf("%ld\n",count(i,j));
			
		}
	}/*
	while (t--){
		gets(s);
		i=s[2]-'0';
		j=s[4]-'0';
		if (s[0]=='C') {
		k=s[6]-'0';
			paint(i,j,k);
		}
		else printf("%d\n",count(i,j));
	}*/
	
	system("pause");
	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