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

Re:1470老是超时,那位高手能帮小弟看看不,谢谢了

Posted by 200609020331 at 2008-12-17 18:29:13 on Problem 1470
In Reply To:1470老是超时,那位高手能帮小弟看看不,谢谢了 Posted by:xiaoxiaoshan at 2008-08-25 17:55:35
> #include <iostream>
> #include <map>
> #include <vector>
> using namespace std;
> int *a,*b; int vnum;
> struct Edge{
> 	int x,y;
> };
> vector<Edge>pvect;
> map<int,int>imap;
> map<int,int>::iterator iter;
> void solve()
> {
> 	int i,j,x,y;
> 	b=new int[vnum+2];
> 	for(i=0;i<vnum+1;i++) b[i]=0;
> 	for(i=0;i<pvect.size();i++){
> 		x=pvect[i].x;
> 		y=pvect[i].y;
> 		b[x]=true;
> 		while(a[x]){
> 			b[a[x]]=true;
> 			x=a[x];
> 		}
> 		while(true){
> 			if(b[y]){
> 				iter=imap.find(y);
> 				if(iter!=imap.end()) iter->second++;
> 				else imap[y]=1;
> 				break;
> 			}
> 			else  y=a[y];
> 		}
> 		for(j=0;j<vnum+1;j++) b[j]=0;
> 	}
> 	delete []b;
> }
> 
> int main()
> {
> 	int i,j,v,u,m;
> 	char c;
> 	Edge pnode;
> 	while(scanf("%d",&vnum)){
> 		a=new int[vnum+2];
> 		for(i=0;i<vnum+1;i++) a[i]=0;
> 		for(i=0;i<vnum;i++){
> 			scanf("%d",&v);
> 			while(scanf("%c",&c)&&c!='(');
> 			scanf("%d",&m);
> 			while(scanf("%c",&c)&&c!=')');
> 			for(j=0;j<m;j++){
> 				scanf("%d",&u);
> 				a[u]=v;
> 			}
> 		}
> 
> 		scanf("%d",&m);
> 		while(m--){
> 			while(scanf("%c",&c)&&c!='(');
> 			scanf("%d%d",&u,&v);
> 			pnode.x=u;pnode.y=v;
> 			pvect.push_back(pnode);
> 			while(scanf("%c",&c)&&c!=')');
> 		}
> 
> 		solve();
> 		for(iter=imap.begin();iter!=imap.end();iter++)
> 			printf("%d:%d\n",iter->first,iter->second);
> 		
> 		delete []a;
> 		imap.clear();
> 		pvect.clear();
> 	}
> 	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