标签:sizeof 一个 搜索 不同 insert turn while clear 方向
#include"stdio.h" #include"string.h" char s[105000]; char a[105000]; int main(){ int i,l,x,now; scanf("%s",s); l=strlen(s); now=97; x=0; for (i=l-1;i>=0;i--){ if (s[i]>=now) { a[x]=s[i]; x++; now=s[i]; } } for (i=x-1;i>=0;i--) printf("%c",a[i]); printf("\n"); }
#include"stdio.h" #include"string.h" #include"vector" using namespace std; int v[505000]; int a[505000]; int main(){ int n,i; scanf("%d",&n); for (i=1;i<=n;i++) {scanf("%d",&a[i]);a[i]+=100000;} memset(v,0,sizeof(v)); for (i=1;i<=(n+1)/2;i++) { if (a[i]-i+1>0) v[a[i]-i+1]++; } for (i=(n+1)/2+1;i<=n;i++) { if (a[i]-(n-i)>0) v[a[i]-(n-i)]++; } int ans=0; for (i=1;i<=500000;i++) if (v[i]>ans) ans=v[i]; printf("%d\n",n-ans); }
#include"stdio.h" #include"string.h" int x[105]; int y[105]; int vis[105]; int father[105]; int getfather(int k){ if (k==father[k]) return k; else father[k]= getfather(father[k]); return father[k]; } int main(){ int n,i,j,a,b,ans; ans=0; scanf("%d",&n); for (i=1;i<=n;i++) father[i]=i; for (i=1;i<=n;i++) scanf("%d %d",&x[i],&y[i]); for (i=1;i<=n;i++) for (j=i+1;j<=n;j++) if (x[i]==x[j]||y[i]==y[j]) { a=getfather(i); b=getfather(j); father[b]=a; } for (i=1;i<=n;i++) father[i]=getfather(father[i]); memset(vis,0,sizeof(vis)); for (i=1;i<=n;i++) if (vis[father[i]]==0){ vis[father[i]]=1; ans++; } printf("%d\n",ans-1); }
#include"stdio.h" #include"string.h" #include"set" #include"algorithm" #define maxn 105000 using namespace std; set<int>s; int a[maxn][21]; int b[maxn]; int sign[50]; struct node{ int wei,sum; }xu[50]; int cmp1(node a,node b){ return a.sum<b.sum; } int main(){ int i,n,x,now,l,j; int ff=0; scanf("%d",&n); for (i=1;i<=n;i++) scanf("%d",&b[i]); memset(a,-1,sizeof(a)); for (i=n;i>=1;i--){ l=0; x=b[i]; if (b[i]==0) ff=1; memset(sign,0,sizeof(sign)); while(x>0){ l++; sign[l]=x%2; x=x/2; } for (j=1;j<=20;j++) if (sign[j]==1) a[i][j]=i; else a[i][j]=a[i+1][j]; } s.clear();/* for (i=1;i<=n;i++){ for (j=1;j<=20;j++) printf("%5d",a[i][j]); printf("\n"); }*/ for(i=1;i<=n;i++) { now=b[i]; for (j=1;j<=20;j++) { xu[j].wei=j; xu[j].sum=a[i][j]; } sort(xu+1,xu+1+20,cmp1); xu[21].sum=-1; for (j=1;j<=20;j++) if (xu[j].sum!=-1) { if (xu[j].sum!=xu[j+1].sum){ now=now|(1<<(xu[j].wei-1)); s.insert(now); }else { now=now|(1<<(xu[j].wei-1)); } } } printf("%d\n",s.size()+ff); }
#include"stdio.h" long long a[105000]; int main(){ long long n,m,i; scanf("%lld %lld",&n,&m); for (i=1;i<=n;i++) scanf("%lld",&a[i]); long long r=1; long long ans=0; for (i=1;i<=n;i++){ while(r<=n&&a[r]-a[i]<=m) r++; if (r-1-i>=2) ans+=(r-1-i)*(r-1-i-1)/2; } printf("%lld\n",ans); }
标签:sizeof 一个 搜索 不同 insert turn while clear 方向
原文地址:https://www.cnblogs.com/nowheretrix/p/8994903.html