Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
查表法,极好的算法,怎么AC不了?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator