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 |
求救,总是TLE!!!#include<iostream> #include<string> using namespace std; string mark, size; int has[5], n; bool flag; typedef struct{ int from, to; }shirts; shirts s[20]; int cToi(const char &ch){ switch(ch){ case 'S':return 0; case 'M':return 1; case 'L':return 2; case 'X':return 3; case 'T':return 4; } return -1; } void dfs(int p){ int i; for(i=s[p].from; i<=s[p].to && !flag; i++){ has[i]--; if(has[i] >= 0){ if(p != n-1) dfs(p+1); else{ flag = true; return; } } has[i]++; } } int main(){ while(cin>>mark){ if(mark == "ENDOFINPUT") break; cin>>n; int i; for(i=0; i<n; i++){ cin>>size; s[i].from = cToi(size[0]); s[i].to = cToi(size[1]); } for(i=0; i<5; i++) cin>>has[i]; cin>>mark; flag = false; dfs(0); if(flag) cout<<"T-shirts rock!"<<endl; else cout<<"I'd rather not wear a shirt anyway..."<<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