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 |
高手给指导一下,这个到底错那儿了?WA了无数次了,谢谢啦#include<stdio.h> #include<stdlib.h> int compare(const void * arg1,const void * arg2); int main() { int a[100005]; int flag[100005]; int i,n,len,j,result; result=0; scanf("%d%d",&n,&len); if(n<0||n>100000||len>10000)return 0; for(i=0;i<n;i++) { scanf("%d",&a[i]); flag[i]=0; } qsort(a,n,sizeof(int),compare); j=0; for(i=0;i<n;i++) { if(flag[i]==1)continue; for(j=i+1;j<n;j++) { if(flag[j]==0&&a[i]+a[j]<=len) { flag[j]=1; break; } } flag[i]=1; result++; } printf("%d",result); return 0; } int compare(const void * arg1,const void * arg2) { return (*((int *)arg1))<(*((int *)arg2))?1:0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator