标签:codeforces e
#include <cstdio> #include <cstring> #include <algorithm> #define N 1005 using namespace std; int f[N]; int n,m,a,b; int main() { int i,j,k; scanf("%d%d%d%d",&n,&m,&a,&b); for(i=1;i<=n;i++) { f[i]=f[i-1]+a; for(j=max(0,i-m);j<i;j++) { f[i]=min(f[i],f[j]+b); } } printf("%d\n",f[n]); return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> using namespace std; long long n,a,b,c,d; int main() { cin>>n>>a>>b; n=n*6ll; if(n<=a*b) { cout<<a*b; printf("\n"); cout<<a<<' '<<b; printf("\n"); return 0; } else { c=n/a; if(a*c<n)c++; d=n/b; if(b*d<n)d++; if(a*c<=b*d) { cout<<a*c; printf("\n"); cout<<a<<' '<<c; printf("\n"); return 0; } else { cout<<b*d; printf("\n"); cout<<d<<' '<<b; printf("\n"); return 0; } } return 0; }
#include <cstdio> #include <cstring> #include <algorithm> #include <iostream> #define N 501000 using namespace std; int n,a[N],ctl[N],ctr[N]; long long sum,suml[N],sumr[N]; long long ans; int main() { int i,j,k; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%d",&a[i]),sum+=a[i]; if(sum%3) { printf("0\n"); return 0; } sum/=3; for(i=1;i<=n;i++) { suml[i]=suml[i-1]+a[i]; ctl[i]=ctl[i-1]; if(suml[i]==sum)ctl[i]++; } for(i=n;i;i--) { sumr[i]=sumr[i+1]+a[i]; ctr[i]=ctr[i+1]; if(sumr[i]==sum)ctr[i]++; } for(i=1;i<n-1;i++) { if(suml[i]==sum)ans+=ctr[i+2]; } cout<<ans; return 0; }
#include <cstdio> #include <algorithm> #define N 5001000 using namespace std; struct KSD { int v,len,next; }e[N],eq[N]; int head[N],headq[N],cnt,cntq,dcount; int crs[N],ans[N]; bool visit[N]; int n,m; void add(int u,int v) { e[++cnt].v=v; e[cnt].len=dcount; e[cnt].next=head[u]; head[u]=cnt; } void addq(int u,int v,int len) { eq[++cntq].v=v; eq[cntq].len=len; eq[cntq].next=headq[u]; headq[u]=cntq; } int f[N],l[N]; inline int find(int x) { if(f[x]==x)return x; int t=f[x]; f[x]=find(f[x]); l[x]=max(l[x],l[t]); return f[x]; } inline void dfs(int x,int p,int ll) { int i; visit[x]=1; for(i=head[x];i;i=e[i].next) { dfs(e[i].v,x,e[i].len); } for(i=headq[x];i;i=eq[i].next) { if(find(eq[i].v)==x&&l[eq[i].v]<=eq[i].len) { ans[i]=1; } } f[x]=p; l[x]=ll; } int main() { // freopen("test.in","r",stdin); int i,j,k; int a,b,c; scanf("%d%d",&n,&m); dcount=1; for(i=1;i<=m;i++) { scanf("%d",&a); if(a==1) { scanf("%d%d",&b,&c); add(c,b); } if(a==2) { scanf("%d",&b); crs[dcount++]=b; } if(a==3) { scanf("%d%d",&b,&c); if(c>=dcount)++cntq; else addq(b,crs[c],c); } } for(i=1;i<=n;i++)f[i]=i; for(i=1;i<=n;i++) { if(!visit[i])dfs(i,i,0); } for(i=1;i<=cntq;i++) { if(ans[i])puts("YES"); else puts("NO"); } return 0; }
标签:codeforces e
原文地址:http://blog.csdn.net/vmurder/article/details/39241959