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 xtu6113 at 2006-07-27 15:09:38 on Problem 2895
#include<iostream>
#include<cstring>
using namespace std;
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};最后一个10(‘Z’+1用于初使化比较
int result[1000];
int main()
{
	for(int i=0;i<1000;i++)
		result[i]=0;
	int tc;
	cin>>tc;
	int k=tc;
	while(k)
	{
		char mes[1001];
		char ch,rch='Z'+1;
		int t,w;
		cin>>t>>w;
		cin.seekg(1);//走到信息行
		cin.getline(mes,1000);
        for(int i=0;i<strlen(mes);i++)
		{
			ch=mes[i];
			if(ch==' ')result[tc-k]+=t;
			if(key[ch-'A']==key[rch-'A'])result[tc-k]+=w+ttime[ch-'A']*t;
			if(key[ch-'A']!=key[rch-'A'])result[tc-k]+=ttime[ch-'A']*t;
			rch=ch;
		}
		k--;
	}
	for(i=0;i<tc;i++)
		cout<<result[i]<<endl;
	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