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

你的想法很好啊,只是输入输出那边错了,我改了一下就ac了

Posted by cch at 2006-11-09 16:45:59 on Problem 2895
In Reply To:查表法,极好的算法,怎么AC不了? Posted by:xtu6113 at 2006-07-27 15:09:38
#include<stdio.h>
#include<string.h>


const int ttime[]={1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,1,2,3,4,1,2,3,1,2,3,4}; 
const int key[]=  {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9,10};

int main()
{
	//freopen("cch.txt","r",stdin);
	char str[1005];
	long count;
	int t,i;
	int p,w;
	char pre,now;
	int length;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d\n",&p,&w);
		gets(str);
		count=0;
		length=strlen(str);
		if(length>0){
			i=0;
			count+=ttime[str[i]-'A']*p;
			pre=str[i];
			i++;
			while(i<length){
				now=str[i];
				if(now==' ')	count+=p;
				else if(key[now-'A']==key[pre-'A'])	count=count+w+ttime[now-'A']*p;
				else if(key[now-'A']!=key[pre-'A'])	count+=ttime[now-'A']*p;
				pre=now;
				i++;
			}
		}
		printf("%ld\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