Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
贴代码。水题#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator