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 dingyaguang117 at 2011-04-09 10:19:37 on Problem 2287 and last updated at 2011-04-09 10:20:45
都按照从大到小排序
1.如果我当前最大的比对面最大的大,拼
2.如果我当前最大的和对面最大的相等
再比较我当前最小的和对对面最小的,
2.1如果我的最小比对面最小的大,先把小的拼掉
2.2如果我的最小比对面最小的小,用我最小的和对面最大的拼掉
2.3如果最小的还是相等,这时要考虑是不是
类似:
1 1
1 1
这种情况,如果是的话,前面的拼掉,
如果是
2 1
2 1这种,
我的1和对面的2拼掉

3.如果我当前最大比对面最大的小,用我最小的和对面最大的拼掉


不知道是不是正确。。。不过能AC

int main()
{
	int N,i,j,ans,eq,a1,a2,b1,b2;
	int A[1005],B[1005],choosed[1005];
	while(scanf("%d",&N),N)
	{
		memset(choosed,0,sizeof(choosed));
		for (i=0;i<N;++i) scanf("%d",A+i);
		for (i=0;i<N;++i) scanf("%d",B+i);
		sort(A,A+N,greater<int>());
		sort(B,B+N,greater<int>());
		eq=ans=i=j=0;
		a1=b1=0;a2=b2=N-1;
		while(a1<=a2)
		{
			if(A[a1]>B[b1])
			{
				ans++;
				a1++;b1++;
			}else if(A[a1]==B[b1])
			{
				if(A[a2]>B[b2])
				{
					ans++;a2--;b2--;
				}else if(A[a2]==B[b2])
				{
					if (A[a2]<B[b1])
					{
						ans--;
						b1++;
						a2--;
					}else
					{
						a1++;b1++;
					}

				}else
				{
					ans--;
					b1++;
					a2--;
				}
			}else
			{
				ans--;
				b1++;
				a2--;
			}
		}

		printf("%d\n",ans*200);
	}
}

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