#include<stdio.h> #include<unordered_map> #define int long long usingnamespace std; constint N=2e5+1;
int n,m,c,ans,p[N],q[N+N],h=1,t; unordered_map<int,int> o;
signedmain() { freopen("sao.in","r",stdin),freopen("sao.out","w",stdout); scanf("%lld%lld",&n,&m),c=m; int i,x; for (i=1; i<=n; i++) scanf("%lld",&x),q[++t]=x,o[x]=0; while (h<=t) { if (!c) break; x=q[h++]; if (o[x]) ans+=o[x],p[c--]=x; if (!o.count(x-1)) o[x-1]=o[x]+1,q[++t]=x-1; if (!o.count(x+1)) o[x+1]=o[x]+1,q[++t]=x+1; } for (i=1,printf("%lld\n",ans); i<=m; i++) printf("%lld ",p[i]); return0; }
#include<stdio.h> #include<algorithm> #define il inline #define ll long long usingnamespace std; constint N=4e6+1; const ll mod=2333333333333333ll;
int n,son[3][N]; ll ans; int to[N+N],nx[N+N],wt[N+N],head[N],sze; ll P[N],Q[N],mxl[3][N],up[N];
il chargc() { staticchar now[1<<20],*S,*T; if (T==S) { T=(S=now)+fread(now,1,1<<20,stdin); if (T==S) return EOF; } return *S++; } il intread() { int res; char c; while ((c=gc())<'0'||c>'9'); res=c^48; while ((c=gc())>='0'&&c<='9') res=(res<<3)+(res<<1)+(c^48); return res; }
il ll cal(ll x,ll y,ll z){return x+y+z-min(x,min(y,z));}
il voidadd(int u,int v,int w){to[++sze]=v,nx[sze]=head[u],wt[sze]=w,head[u]=sze;}
il voiddfs1(int u,int F) { ll l1=0,l2=0,l3=0; int i,v,w,s1=0,s2=0,s3=0; for (i=head[u]; i; i=nx[i]) { if ((v=to[i])==F) continue; w=wt[i],dfs1(v,u),P[u]=max(P[u],P[v]); if (mxl[0][v]+1ll*w>l1) s3=s2,s2=s1,s1=v,l3=l2,l2=l1,l1=mxl[0][v]+1ll*w; elseif (mxl[0][v]+1ll*w>l2) s3=s2,s2=v,l3=l2,l2=mxl[0][v]+1ll*w; elseif (mxl[0][v]+1ll*w>l3) s3=v,l3=mxl[0][v]+1ll*w; } mxl[0][u]=l1,mxl[1][u]=l2,mxl[2][u]=l3; son[0][u]=s1,son[1][u]=s2,son[2][u]=s3; P[u]=max(P[u],l1+l2); }
il voiddfs2(int u,int F) { ll l1=0,l2=0; int i,v,w,s1=0,s2=0; for (i=head[u]; i; i=nx[i]) { if ((v=to[i])==F) continue; w=wt[i]; if (P[v]>l1) s2=s1,s1=v,l2=l1,l1=P[v]; elseif (P[v]>l2) s2=v,l2=P[v]; if (v==son[0][u]) up[v]=1ll*w+max(up[u],mxl[1][u]),Q[v]=max(Q[u],cal(up[u],mxl[1][u],mxl[2][u])); else { up[v]=1ll*w+max(up[u],mxl[0][u]); if (v==son[1][u]) Q[v]=max(Q[u],cal(up[u],mxl[0][u],mxl[2][u])); else Q[v]=max(Q[u],cal(up[u],mxl[0][u],mxl[1][u])); } } for (i=head[u]; i; i=nx[i]) { if ((v=to[i])==F) continue; if (v==s1) Q[v]=max(Q[v],l2); else Q[v]=max(Q[v],l1); dfs2(v,u); } }
il voidgetans(int u,int F) { int i,v; for (i=head[u]; i; i=nx[i]) if ((v=to[i])!=F) ans=(ans+23333ll*max(P[v],Q[v])+2333ll*min(P[v],Q[v]))%mod,getans(v,u); }
intmain() { freopen("outlaw.in","r",stdin),freopen("outlaw.out","w",stdout); n=read(); int i,u,v,w; for (i=1; i<n; i++) { u=read(),v=read(),w=read(),add(u,v,w),add(v,u,w); ans=(ans+233ll*i*i+23ll*i+2ll)%mod; } dfs1(1,0),dfs2(1,0); getans(1,0),printf("%lld",ans); return0; }
T3 为美丽的阿克塞尔献上爆裂烟火(explosion)
题意
在平面上有一个以原点为圆心半径为 r 的圆和 n 个点。对于任意两个不同点 u,v,他们之间有连边当且仅当过 u,v 的直线与给定的圆没有交,求这 n 组成的图的最大团(极大完全子图)。
#include<stdio.h> #include<math.h> #include<algorithm> #define il inline #define db double usingnamespace std; constint N=2001; const db pi=acos(-1.0);
int n,ans; db CR; structnode{db x,y;}P[N]; db l[N],r[N],rr[N],lis[N],L,R; int T,A[N],ok[N];
il boolbh(db l,db r,db x) { if (l<r) return l<x&&x<r; return (x>l)||(x<r); }
il boolcmp1(int a,int b){return l[a]<l[b];}
il boolcmp2(int a,int b) { if (a>L&&b>L||a<R&&b<R) return l[a]<l[b]; return l[a]>L; }
il intfind(int x,int len) { int le=1,ri=len,mid; while (le<ri) { mid=le+ri>>1; if (lis[mid]>=rr[x]) ri=mid; else le=mid+1; } return le; }
il intLIS() { int i,res=1; for (i=1; i<=A[0]; i++) { rr[i]=r[A[i]]-L; if (rr[i]<0) rr[i]+=2*pi; } for (i=2,lis[1]=rr[1]; i<=A[0]; i++) { if (rr[i]>lis[res]) lis[++res]=rr[i]; else lis[find(i,res)]=rr[i]; } return res; }
intmain() { freopen("explosion.in","r",stdin),freopen("explosion.out","w",stdout); scanf("%d%lf",&n,&CR); int i,j; db AZ,del; for (i=1; i<=n; i++) scanf("%lf%lf",&P[i].x,&P[i].y); for (i=1; i<=n; i++) { AZ=atan2(P[i].y,P[i].x),del=fabs(acos(CR/sqrt(P[i].x*P[i].x+P[i].y*P[i].y))); l[i]=AZ-del,r[i]=AZ+del; if (l[i]<-pi) l[i]+=pi*2; if (r[i]>pi) r[i]-=pi*2; } for (i=T=1; i<=n; i++,T++) { for (j=1,A[A[0]=1]=i; j<=n; j++) { if (i!=j&&bh(l[i],r[i],l[j])&&!bh(l[i],r[i],r[j])) A[++A[0]]=j; elseif (i!=j&&bh(l[i],r[i],r[j])&&!bh(l[i],r[i],l[j])) swap(l[j],r[j]),A[++A[0]]=j,ok[j]=T; } L=l[i],R=r[i],sort(A+1,A+A[0]+1,L<R?cmp1:cmp2),ans=max(ans,LIS()); for (j=1; j<=A[0]; j++) if (ok[j]==T) swap(l[j],r[j]); } printf("%d",ans); return0; }
#include<stdio.h> #include<algorithm> #define il inline #define int long long usingnamespace std; constint N=201,M=265000;
int n,m,L,R,ans,A[N][N],U[N],V[N]; int to[M],nx[M],cap[M],head[M],sze; int S,T,h,t,q[M],it[M],lev[M];
il voidadd(int u,int v,int c){to[++sze]=v,nx[sze]=head[u],cap[sze]=c,head[u]=sze;}
il voidadde(int u,int v,int c){add(u,v,c),add(v,u,0);}
il voidaddlr(int u,int v,int l,int r){adde(S,v,l),adde(u,T,l),adde(u,v,r-l);}
il intbfs() { int i,u,v; for (i=1; i<=n+m+4; i++) lev[i]=0; q[h=t=lev[S]=1]=S; while (h<=t) for (i=head[u=q[h++]]; i; i=nx[i]) if (cap[i]&&!lev[v=to[i]]) lev[v]=lev[u]+1,q[++t]=v; return lev[T]; }
il intdfs(int u,int f) { if (u==T) return f; int z,res=0; for (int &i=it[u]; i; i=nx[i]) if (cap[i]&&lev[to[i]]==lev[u]+1&&(z=dfs(to[i],min(f-res,cap[i])))) { cap[i]-=z,cap[i^1]+=z,res+=z; if (res==f) break; } return res; }
il intdinic() { int i,res=0,f; while (bfs()) { for (i=1; i<=n+m+4; i++) it[i]=head[i]; while (f=dfs(S,1e9)) res+=f; } return res; }
il intcheck(int x) { sze=1; int i,j,okf=0; for (i=1; i<=n+m+4; i++) head[i]=0; for (i=1; i<=n; i++) for (j=1; j<=m; j++) addlr(i+4,n+j+4,L,R),okf+=L; for (i=1; i<=n; i++) addlr(3,i+4,max(U[i]-x,0ll),U[i]+x),okf+=max(U[i]-x,0ll); for (j=1; j<=m; j++) addlr(n+j+4,4,max(V[j]-x,0ll),V[j]+x),okf+=max(V[j]-x,0ll); addlr(4,3,0ll,1e9); returndinic()==okf; }
signedmain() { freopen("overvit.in","r",stdin),freopen("overvit.out","w",stdout); scanf("%d%d",&n,&m),S=1,T=2; int i,j,p=1,l=0,r=2e5,mid; for (i=1; i<=n; i++) for (j=1; j<=m; j++) scanf("%d",A[i]+j); scanf("%d%d",&L,&R); for (i=1; i<=n; i++) for (j=1; j<=m; j++) U[i]+=A[i][j]; for (j=1; j<=m; j++) for (i=1; i<=n; i++) V[j]+=A[i][j]; while (l<=r) { mid=l+r>>1; if (check(mid)) ans=mid,r=mid-1; else l=mid+1; } printf("%lld\n",ans),check(ans); for (i=1; i<=n; puts(""),i++) for (j=1; j<=m; j++) p+=6,printf("%lld ",cap[p]+L); return0; }