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 zhb_msqx at 2007-09-18 17:18:03 on Problem 2259
#include <iostream>
#include <fstream>
using namespace std;

const int max=1100;

int t;
int a[max][max],num[max]; //a[][]存储i组的j个元素,num存储i组有多少个元素
int que[max][max];//队列
int quesize[max];   //队列的大小
int group[max];    //组号

int groupnum;




int schgroup(int p){
	int i,j;

	for(i=0;i<t;i++){
		for(j=0;j<num[i];j++){
			if(a[i][j]==p)return i;
		}
	}
	return -1;
}



void init(){

	memset(a,0,sizeof(a));
	memset(num,0,sizeof(num));
	memset(que,0,sizeof(que));
	memset(quesize,0,sizeof(quesize));
	memset(group,0,sizeof(group));
	groupnum=0;

}

int main(){
//	ifstream cin("data.txt");
	int testcase=1;
	while(1){
		cin>>t;
		if(t==0)break;
		int i,j;
		

		for(i=0;i<t;i++){
			cin>>num[i];
			for(j=0;j<num[i];j++){
				cin>>a[i][j];
			//	cout<<a[i][j]<<" ";
			}
		//	cout<<endl;
		}
		cout<<"Scenario #"<<testcase++<<endl;
		while(1){
			char comd[20];
			cin>>comd;
			if(comd[0]=='S')break;
			if(comd[0]=='E'){//perform enqueue
				int good;
				cin>>good;
				int gp=schgroup(good);
				bool find=false;
				for(i=0;i<groupnum;i++){
					if(gp==group[i]){
						find=true;
						break;
					}
				}
				if(find){
					que[i][quesize[i]]=good;
					quesize[i]++;

				}else{
					group[groupnum]=gp;
					quesize[groupnum]=1;
					que[groupnum][0]=good;
					groupnum++;
				}
			}else if(comd[0]=='D'){
				cout<<que[0][0]<<endl;
				if(quesize[0]==1){
					for(i=1;i<groupnum;i++){
						//memcpy(que[i-1],que[i],max);
						for(j=0;j<quesize[i];j++){
							que[i-1][j]=que[i][j];
						}
						quesize[i-1]=quesize[i];
					}
					groupnum--;
				}else{
					for(i=1;i<quesize[0];i++){
						que[0][i-1]=que[0][i];
					}
					quesize[0]--;
				}
				//perform dequeue
			}

		}
		cout<<endl;
	}
	return 1;
}

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