constint maxn=105; int n,d,a[maxn]; intmain(){ scanf("%d%d",&n,&d); for (int i=1;i<=n;i++) scanf("%d",&a[i]); sort(a+1,a+1+n); int ans=2; for (int i=2;i<=n;i++) if (a[i]-a[i-1]==2*d) ans++;else if (a[i]-a[i-1]>2*d) ans+=2; printf("%d",ans); return0; }
B. Sonya and Exhibition
一开始想了好久,后来发现直接010101……就好了
1 2 3 4 5 6 7
#include<cstdio>
intmain(){ int n;scanf("%d",&n); for (int i=1;i<=n;i++) putchar('0'+(i&1)); return0; }
constint maxn=200005; int n,a[maxn],N; bool vis[maxn]; structdata{ int x,ty; data (int _x=0,int _ty=0):x(_x),ty(_ty) {} booloperator<(const data&b)const {return x<b.x;} }b[maxn]; intmain(){ scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&a[i]); for (int i=1;i<=n;i++) if (!vis[a[i]]) b[++N]=data(i,0),vis[a[i]]=1; cl(vis,0); int m=0; for (int i=n;i>=1;i--) if (!vis[a[i]]) m++,b[++N]=data(i,1),vis[a[i]]=1; sort(b+1,b+1+N); ll ans=0; for (int i=1,j;i<=N;i=j){ int num[2]; num[0]=num[1]=0; for (j=i;j<=N&&b[i].x==b[j].x;j++) num[b[j].ty]++; m-=num[1]; ans+=num[0]*m; } printf("%lld",ans); return0; }