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

改成这样还是错。

Posted by 15017547261 at 2009-02-08 20:29:36 on Problem 1962
In Reply To:为什么总是WA啊。 Posted by:15017547261 at 2009-02-08 18:51:10
#include <iostream>
using namespace std;
int main(){
	int t,output[200000],l=0,c[20000],d[20000];
	char cmd;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		cin>>cmd;
		memset(c,0,sizeof(c));
		memset(d,0,sizeof(d));
		while(cmd!='O'){
			if(cmd=='E'){
				int p;
				cin>>p;
				output[l++]=d[p];
			}else{
				int p,q;
				cin>>p>>q;
				d[p]=abs(p-q)%1000+d[q];
				if(c[q]) c[p]=c[q];
				else c[p]=q;
				for(int i=1;i<=n;i++){
					if(c[i]==p){
						c[i]=c[p];
						d[i]+=d[p];
					}
				}
			}
			cin>>cmd;
		}
	}
	for(int i=0;i<l;i++) cout<<output[i]<<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