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 |
C++ STL写法 带劲代码//我的代码中,非主代码的部分很长,凑合看一下 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; namespace Flandre_Scarlet { #define N 155555 #define F(i,l,r) for(int i=l;i<=r;++i) #define D(i,r,l) for(int i=r;i>=l;--i) #define Fs(i,l,r,c) for(int i=l;i<=r;c) #define Ds(i,r,l,c) for(int i=r;i>=l;c) #define Tra(i,u) for(int i=G.Start(u),__v=G.To(i);~i;i=G.Next(i),__v=G.To(i)) #define MEM(x,a) memset(x,a,sizeof(x)) #define FK(x) MEM(x,0) void R1(int &x) { x=0;char c=getchar();int f=1; while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar(); while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); x=(f==1)?x:-x; } int r,n,a[N]; void Input() { F(i,1,n) R1(a[i]); } void Soviet() //这个函数是主代码 { sort(a+1,a+n+1); int i,j; int ans=0; for(i=1;i<=n;) { j=upper_bound(a+i,a+n+1,a[i]+r)-a-1; i=upper_bound(a+j,a+n+1,a[j]+r)-a; ++ans; } printf("%d\n",ans); } #define Flan void Flan IsMyWife() { while(~scanf("%d%d",&r,&n) and (r!=-1 and n!=-1)) { Input(); Soviet(); } } } int main() { Flandre_Scarlet::IsMyWife(); getchar();getchar(); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator