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" using namespace std; const int ms=1001; int a[ms]; int r,n; void solve() { int i=0,ans=0,l; sort(a,a+n); l=a[0]; while(i<n) { while(i<n&&l+r>=a[i]) i++; l=a[i-1]; while(i<n&&l+r>=a[i]) i++; l=a[i]; ans++; } printf("%d\n",ans); return ; } int main() { while(scanf("%d%d",&r,&n)==2) { if(r==-1&&n==-1) break; for(int i=0;i<n;i++) scanf("%d",&a[i]); solve(); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator