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

为什么总是tle阿,暴力阿,为什么阿,代码贴上

Posted by denganliang at 2011-03-29 20:11:33 on Problem 2858
#include <stdio.h>
#include <string.h>
int value[27]={0};
char s[100002][11];
int main(){
	int i,j,k,m,n,len,p,v,max,flag;
	char temp;
	scanf("%d",&n);
	j=0;
	for(i=0;i<n;i++){
	scanf("%s",s[j++]);
	if(strlen(s[j])>10) j--;
	}
	n=j;
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d",&p);
		for(j=0;j<27;j++) 
		value[j]=-200;
		for(j=0;j<p;j++){
			getchar();
			scanf("%c %d",&temp,&v);
			value[temp-'a']=v;
			}
		max=0;
		for(j=0;j<n;j++)
		   {
			   len=strlen(s[j]);
			   if(len>p) continue;
			   v=0;
			   flag=0;
			   for(k=0;k<len;k++)
			   {
				   if(value[s[j][k]-'a']==-200) {
					   flag=1;
					   break;
					   }
				   v+=value[s[j][k]-'a'];
				   }
				   if(flag==1) continue;
			  if(max<v) max=v;
			   }
	    printf("%d\n",max);
		}
	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