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 Larnya at 2010-04-05 12:57:49 on Problem 2584 and last updated at 2010-04-05 13:47:47
#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:
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