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 dou116703623 at 2008-10-17 17:14:00 on Problem 2782
最一般的方法就可以啊,排序嘛,才79MS啊
#include<iostream>
#include<algorithm>
using namespace std;
int a[100005];
int main()
{
	int n,len;
	scanf("%d%d",&n,&len);
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
	}
	
	sort(a,a+n);
	int j=0;
	int ans=0;
	
	for(i=n-1;i>=0;i--)
	{
		if(i==j) {ans++;break;}
		if(a[i]+a[j]<=len) j++;
		ans++;
		if(i==j) break;
	}
	printf("%d\n",ans);
	
	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