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 ddddd at 2003-07-17 12:05:04 on Problem 1029
#include<iostream.h>
#include<math.h>

struct{
	int present;
	int weight;
	int exclude;
}a[1005];

int b[1005];

void process(int num){
	char op;
	for(int i=0;i<num*2;i++){
		cin>>b[i];
		a[b[i]].present=1;
	}
	cin>>op;
	switch(op){
	case '>':
		for(i=0;i<num;i++)
			if(!a[b[i]].exclude)
				a[b[i]].weight+=1;
		for(;i<num*2;i++)
			if(!a[b[i]].exclude)
				a[b[i]].weight-=1;
		break;
	case '<':
		for(i=0;i<num;i++)
			if(!a[b[i]].exclude)
				a[b[i]].weight-=1;
		for(;i<num*2;i++)
			if(!a[b[i]].exclude)
				a[b[i]].weight+=1;
		break;
	case '=':
		for(i=0;i<num*2;i++)
			a[b[i]].exclude=1;
	}
}

void judge(int n){
	int time=0,max=0,t;
	for(int i=1;i<n+1;i++)
		if(a[i].present&&!a[i].exclude){
			if(abs(a[i].weight)>max){
				max=abs(a[i].weight);
				t=i;
				time=0;
			}
			else if(abs(a[i].weight)==max)
				time++;
		}
	if(max!=0&&!time)
		cout<<t;
	else
		cout<<0;
}
	
int main(){
	int n,k,num;
	cin>>n>>k;
	for(int j=1;j<=n;j++)
		a[j].present=a[j].exclude=a[j].weight=0;
	for(int i=0;i<k;i++){
		cin>>num;
		process(num);
	}
	judge(n);
	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