标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int n,r,ans; 6 int a[1010]; 7 int cmax(int x,int y){return x>y?x:y;} 8 int main() 9 { 10 scanf("%d%d",&r,&n); 11 while (n!=-1 && r!=-1) 12 { 13 memset(a,0,sizeof(a)); 14 for (int i=1;i<=n;i++) scanf("%d",&a[i]); 15 sort(a+1,a+n+1); 16 int i=1;ans=0; 17 while (i<=n) 18 { 19 int s=a[i++]; 20 while (i<=n && a[i]<=s+r) i++; 21 int p=a[i-1]; 22 while (i<=n && a[i]<=p+r) i++; 23 ans++; 24 } 25 printf("%d\n",ans); 26 scanf("%d%d",&r,&n); 27 } 28 return 0; 29 }
标签:
原文地址:http://www.cnblogs.com/NicoleLam/p/4174892.html