标签:
bzoj1334:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } int f[100005]; int a[100005]; int main(){ int n=read(),sum=0,ans=-1; rep(i,1,n) a[i]=read(),sum+=a[i]; sort(a+1,a+n+1); f[0]=1; dwn(i,n,1) dwn(j,sum/2+a[i],a[i]) if(f[j-a[i]]) f[j]=1,ans=max(ans,j); printf("%d\n",ans); return 0; }
bzoj1339:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define clr(x,c) memset(x,c,sizeof(x)) #define qwq(x) for(edge *o=head[x];o;o=o->next) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } const int nmax=405; const int maxn=1e5+5; const int inf=0x7f7f7f7f; struct edge{ int to,cap;edge *next,*rev; }; edge edges[maxn],*pt=edges,*head[nmax],*cur[nmax],*p[nmax]; int cnt[nmax],h[nmax]; void add(int u,int v,int d){ pt->to=v;pt->cap=d;pt->next=head[u];head[u]=pt++; } void adde(int u,int v,int d){ add(u,v,d);add(v,u,0);head[u]->rev=head[v];head[v]->rev=head[u]; } int maxflow(int s,int t,int n){ clr(cnt,0);cnt[0]=n;clr(h,0); int flow=0,a=inf,x=s;edge *e; while(h[s]<n){ for(e=cur[x];e;e=e->next) if(e->cap>0&&h[e->to]+1==h[x]) break; if(e){ p[e->to]=cur[x]=e;a=min(a,e->cap);x=e->to; if(x==t){ while(x!=s) p[x]->cap-=a,p[x]->rev->cap+=a,x=p[x]->rev->to; flow+=a,a=inf; } }else{ if(!--cnt[h[x]]) break; h[x]=n; for(e=head[x];e;e=e->next) if(e->cap>0&&h[x]>h[e->to]+1) cur[x]=e,h[x]=h[e->to]+1; cnt[h[x]]++; if(x!=s) x=p[x]->rev->to; } } return flow; } int main(){ int n=read(),m=read(),s=read(),t=read();t+=n; rep(i,1,n) adde(i,i+n,read()); rep(i,1,m){ int u=read(),v=read(); adde(u+n,v,inf);adde(v+n,u,inf); } printf("%d\n",maxflow(s,t,n+n)); return 0; }
bzoj1342:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } char num[7]; void print(int x){ int len=0; while(x){ num[++len]=x%10+‘0‘;x/=10; } dwn(i,len,1) putchar(num[i]);putchar(‘\n‘); } const int nmax=1000005; int a[nmax],q[nmax],Q[nmax]; int main(){ int n=read(),m=read(),c=read(); rep(i,1,n) a[i]=read(); int s=1,t=1,l=1,r=1;q[1]=1,Q[1]=1; bool flag=false; rep(i,2,n){ while(s<=t&&q[s]+m<=i) s++; while(s<=t&&a[q[t]]<=a[i]) t--; q[++t]=i; while(l<=r&&Q[l]+m<=i) l++; while(l<=r&&a[Q[r]]>=a[i]) r--; Q[++r]=i; if(a[q[s]]-a[Q[l]]<=c&&i>=m) flag=true,print(i-m+1); // printf("%d:%d %d\n",i,q[s],Q[l]); } if(!flag) printf("NONE\n"); return 0; }
bzoj1349:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define ll long long int main(){ ll a;scanf("%lld",&a); ll tmp=(ll)sqrt(a); if(tmp*tmp==a) { printf("%lld\n",tmp); }else printf("%lld\n",tmp+1); return 0; }
bzoj1355:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) const int nmax=1000006; char s[nmax]; int ch[nmax][26],fail[nmax],F[nmax],pt=0; void insert(){ int len=strlen(s),t=0; rep(i,0,len-1) { if(!ch[t][s[i]-‘a‘]) ch[t][s[i]-‘a‘]=++pt; t=ch[t][s[i]-‘a‘]; F[t]=i+1; } } queue<int>q;int n; void getfail(){ q.push(0);fail[0]=0; while(!q.empty()){ int x=q.front();q.pop(); rep(i,0,25){ if(ch[x][i]) q.push(ch[x][i]),fail[ch[x][i]]=x==0?0:ch[fail[x]][i]; else ch[x][i]=x==0?0:ch[fail[x]][i]; } } printf("%d\n",n-F[fail[n]]); } int mian(){ scanf("%d",&n);scanf("%s",s);insert();getfail(); return 0; }
bzoj1369:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) #define qwq(x) for(edge *o=head[x];o;o=o->next) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } const int nmax=10005; const int inf=0x7f7f7f7f; struct edge{ int to;edge *next; }; edge edges[nmax<<1],*pt=edges,*head[nmax]; int dp[nmax][4]; void add(int u,int v){ pt->to=v;pt->next=head[u];head[u]=pt++; pt->to=u;pt->next=head[v];head[v]=pt++; } void dfs(int x,int fa){ qwq(x) if(o->to!=fa){ dfs(o->to,x); rep(i,1,3){ int ans=inf; rep(j,1,3) if(i!=j) ans=min(ans,dp[o->to][j]); dp[x][i]+=ans; } } rep(i,1,3) dp[x][i]+=i; } int main(){ int n=read(); rep(i,1,n-1){ int u=read(),v=read();add(u,v); } dfs(1,0); int ans=inf; rep(i,1,3) ans=min(ans,dp[1][i]); printf("%d\n",ans); return 0; }
bzoj1370:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } const int nmax=2005; int fa[nmax]; char s[5]; int find(int x){ return fa[x]==x?x:fa[x]=find(fa[x]); } int main(){ int n=read(),m=read(),u,v; rep(i,1,n+n) fa[i]=i; rep(i,1,m){ scanf("%s",s);u=read(),v=read(); if(s[0]==‘F‘) fa[find(u)]=find(v); else fa[find(u+n)]=find(v),fa[find(v+n)]=find(u); } rep(i,1,n) find(i); sort(fa+1,fa+n+1); int ans=1; rep(i,2,n) if(fa[i]!=fa[i-1]) ans++; printf("%d\n",ans); return 0; }
bzoj1375:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<queue> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) #define qwq(x) for(edge *o=head[x];o;o=o->next) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } const int nmax=105; const int maxn=605; const int inf=0x7f7f7f7f; struct edge{ int to,dist,cost;edge *next; }; edge edges[maxn],*pt=edges,*head[nmax]; bool inq[nmax][41000];int f[nmax][41000],n; void adde(int u,int v,int d,int w){ pt->to=v;pt->dist=d;pt->cost=w;pt->next=head[u],head[u]=pt++; pt->to=u;pt->dist=d;pt->cost=w;pt->next=head[v],head[v]=pt++; } struct node{ int u,d; node(int u,int d):u(u),d(d){} }; queue<node>q; void spfa(int s,int t){ clr(f,0x7f);f[s][0]=0;inq[s][0]=1;q.push(node(s,0)); while(!q.empty()){ node x=q.front();q.pop();inq[x.u][x.d]=0; if(x.d>n*nmax-n) continue; qwq(x.u) if(f[x.u][x.d]+o->cost<f[o->to][x.d+o->dist]){ f[o->to][x.d+o->dist]=f[x.u][x.d]+o->cost; if(!inq[o->to][x.d+o->dist]) { q.push(node(o->to,x.d+o->dist)); inq[o->to][x.d+o->dist]=1; } } } } int main(){ n=read();int m=read(),s=read(),t=read(),u,v,d,w,dsum=0,csum=0; rep(i,1,m) u=read(),v=read(),d=read(),w=read(),adde(u,v,d,w); spfa(s,t); int ans=0,nmin=inf; rep(i,0,n*nmax-n) { if(f[t][i]==inf) continue; if(f[t][i]>=nmin) continue; nmin=f[t][i];ans++; } printf("%d\n",ans); return 0; }
bzoj1391:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) #define dwn(i,s,t) for(int i=s;i>=t;i--) #define clr(x,c) memset(x,c,sizeof(x)) #define qwq(x) for(edge *o=head[x];o;o=o->next) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } const int nmax=4005; const int maxn=3000005; const int inf=0x7f7f7f7f; struct edge{ int to,cap;edge *next,*rev; }; edge edges[maxn],*pt=edges,*head[nmax],*cur[nmax],*p[nmax]; int cnt[nmax],h[nmax]; void add(int u,int v,int d){ pt->to=v;pt->cap=d;pt->next=head[u];head[u]=pt++; } void adde(int u,int v,int d){ add(u,v,d);add(v,u,0);head[u]->rev=head[v];head[v]->rev=head[u]; } int maxflow(int s,int t,int n){ clr(cnt,0);clr(h,0);cnt[0]=n; int flow=0,a=inf,x=s;edge *e; while(h[s]<n){ for(e=cur[x];e;e=e->next) if(e->cap>0&&h[x]==h[e->to]+1) break; if(e){ cur[x]=p[e->to]=e;a=min(a,e->cap);x=e->to; if(x==t) { while(x!=s) p[x]->cap-=a,p[x]->rev->cap+=a,x=p[x]->rev->to; flow+=a,a=inf; } }else{ if(!--cnt[h[x]]) break; h[x]=n; for(e=head[x];e;e=e->next) if(e->cap>0&&h[x]>h[e->to]+1) h[x]=h[e->to]+1,cur[x]=e; cnt[h[x]]++; if(x!=s) x=p[x]->rev->to; } } return flow; } int main(){ int n=read(),m=read(),u,v,d,w,s=0,t=n+m+1,ans=0; rep(i,1,n){ u=read(),v=read(); rep(j,1,v) d=read(),w=read(),adde(i,d+n,w); adde(s,i,u);ans+=u; } rep(i,1,m) u=read(),adde(i+n,t,u); printf("%d\n",ans-maxflow(s,t,t+1)); return 0; }
bzoj1345:
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; #define rep(i,s,t) for(int i=s;i<=t;i++) int read(){ int x=0;char c=getchar(); while(!isdigit(c)) c=getchar(); while(isdigit(c)) x=x*10+c-‘0‘,c=getchar(); return x; } int a[1000005]; int main(){ int n=read();a[1]=read();long long ans=0; rep(i,2,n) a[i]=read(),ans+=max(a[i],a[i-1]); printf("%lld\n",ans); return 0; }
感动啊。。。被带着飞感动啊。。。
标签:
原文地址:http://www.cnblogs.com/fighting-to-the-end/p/5731101.html