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 sunzuhan at 2010-10-15 21:46:52 on Problem 2287
#include<iostream>
 #include<cstdio>
 #include<cstring>
 #include<algorithm>
 #include<cstdlib>
 
using namespace std;

int cmp(const void *a,const void *b)
{
	return *(int *)b-*(int *)a;
}
int tian[1001];
int king[1001];
int main()
{
	while(1)
	{
		int n;
		int i,j;
		cin>>n;
		if(!n)
			break;
			
		for(i=1;i<=n;i++)
			cin>>tian[i];
		for(i=1;i<=n;i++)
			cin>>king[i];
			
		qsort(tian+1,n,sizeof(tian[0]),cmp);
		qsort(king+1,n,sizeof(king[0]),cmp);
		
		int def=0,win=0;
		int l,r;
		i=l=1;
		j=r=n;
		while(l<=r)
		{
			if(tian[l]>king[i])
			{
				win++;
				l++;
				i++;
			}
			else if(tian[l]<king[i])
			{
				if(tian[r]<king[j])
				{
					def++;
					r--;
					i++;
				}
				else{
					def++;
					l++;
					i++;
				}
			}
			else {
				if(tian[r]<king[j])
				{
					def++;
					r--;
					i++;
				}
				else
				{
					l++;
					r++;
				}
			}
		}
		cout<<(win-def)*200<<endl;
	}
	return 0;
}
求数据。简单的贪心怎么总是WA?

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