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 <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #define M 50005 #define INF 100000000 using namespace std; int n,m,a[M]; bool cmp(const int t1,const int t2) { return abs(double(t1))<abs(double(t2)); } int main() { // freopen("1.txt","r",stdin); while(scanf("%d%d",&m,&n)!=EOF) { int i,j,k,p=0; for(i=1,j=INF;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n,cmp); for(i=1;i<=n;i++) { p+=abs(a[i]-a[i-1]); if(p>m) break; } printf("%d\n",i-1); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator