1 solutions
-
0
C++ :
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; int n,r; int a[1010]; int main(){ cin>>n>>r; for(int i=1;i<=n;i++)cin>>a[i]; sort(a+1,a+1+n); //for(int i=1;i<=n;i++)cout<<a[i]<<' '; int x=0,num=0; for(int i=1;i<=n&&x<10000;){ //cout<<i<<' '; while(a[i]-r<=x){ i++; } num++; x=a[i-1]+r; } cout<<num; return 0; }
Pascal :
var i,j,n,r,ans,t:longint; x,y:array[0..1001]of longint; procedure qsort(l,r:longint); var i,j,mid,tmp:longint; begin i:=l;j:=r; mid:=x[(l+r) div 2]; repeat while x[i]<mid do inc(i); while x[j]>mid do dec(j); if i<=j then begin tmp:=x[i];x[i]:=x[j];x[j]:=tmp; tmp:=y[i];y[i]:=y[j];y[j]:=tmp; inc(i);dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; begin readln(n,r); for i:=1 to n do begin read(t); x[i]:=t-r; y[i]:=t+r; end; qsort(1,n); if n=1 then begin write(1);halt; end; ans:=0; t:=0; for i:=2 to n do if (x[i-1]<=t)and(x[i]>t) then begin inc(ans); t:=y[i-1]; end; if t<10000 then inc(ans); write(ans); end.
- 1
Information
- ID
- 701
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By