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 suhang at 2009-12-27 09:55:56 on Problem 3618
#include <cstdio>
#include <algorithm>

const int maxn=51234;

int t,n,a[maxn],b[maxn];

void swap(int &x,int &y)
{
	int t=x;x=y;y=t;
}

void qsort(int l,int r)
{
	int i=l,j=r,x=a[(i+j)/2];
	while (i<=j)
	{
		while (a[i]<x) i++;
		while (a[j]>x) j--;
		if (i<=j)
		{
			swap(a[i],a[j]);
			swap(b[i],b[j]);
			i++;
			j--;
		}
	}
	if (i<r) qsort(i,r);
	if (j>l) qsort(l,j);
}

int main()
{
	freopen("p3618.in","r",stdin);
	freopen("p3618.out","w",stdout);
	scanf("%d%d",&t,&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		a[i]=abs(b[i]);
	}
	qsort(1,n);
	int x=0,ans=0,i=1;
	while (t>0)
	{
		if (abs(x-b[i])>t) break;
		else
		{
			t-=abs(x-b[i]);
			x=b[i];
			i++;
			ans++;
		}
	}
	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