码迷,mamicode.com
首页 > 其他好文 > 详细

CXMS ZZ round

时间:2018-05-13 21:05:05      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:car   return   分享图片   har   freopen   printf   --   \n   open   

T1:

技术分享图片
#include<bits/stdc++.h>
int a[2000007],og,ma,n,op,opt,tot;
long long sum;
using namespace std;
signed main () {
    freopen("building.in","r",stdin);
    freopen("building.out","w",stdout);
    scanf("%d",&n);
    for (int i=1;i<n;i++)  {
      scanf("%d",a+i); sum+=max(ma,a[i]);
      if (ma+2<a[i]) {
          printf("0\n");return 0;
      }  
      if (ma+1==a[i]) {
          ma=a[i]; og=i;
      } else if (ma+2==a[i]) {
          if (!op) {
          op=1; ma=a[i];  opt=i-og; og=i; }
          else {
              printf("0\n");return 0;
          }
      } 
    }
    if (op==1) {
     printf("%d\n",opt); return 0;}
    printf("%lld\n",sum+1);
    return 0;
}
View Code

T2:

技术分享图片
#include<bits/stdc++.h>
#define eho(x) for(int ii=head[(x)];ii;ii=net[ii])
#define v fall[ii]
#define N 4007
#define int long long
struct Node{
    int id,to,x;
    bool operator <(const Node&X)const{
      return x<X.x;
    }
}p[N<<1];
#define M 400007
int fall[M<<1],net[M<<1],head[N],cost[M<<1],der[N];
int usd[N];
int a[N],tot,n,m;
inline void adds(int x,int y,int co){
    assert(1<=x&&x<=n&&1<=y&&y<=n&&x!=y);
    der[x]++;fall[++tot]=y; net[tot]=head[x]; head[x]=tot; cost[tot]=co;
    der[y]++;fall[++tot]=x; net[tot]=head[y]; head[y]=tot; cost[tot]=co;
}
int find() {
    static int tot=1;
    for (;tot<=n;tot++)  if (der[tot]<2&&!usd[tot]) return tot++; 
}
using namespace std;
int k,pp[N],ma[N],f[N][N];
#define inf (1ll<<30)
#define LL long long
LL anw,ans;int cxs;
#define sight(x) (‘0‘<=x&&x<=‘9‘)
inline void read(int &x){
    static char c;
    for (c=getchar();!sight(c);c=getchar());
    for (x=0;sight(c);c=getchar())x=x*10+c-48;
}
void write(LL x){if (x<10) {putchar(0+x); return;} write(x/10); putchar(0+x%10);}
inline void writeln(LL x){ if (x<0) putchar(-),x*=-1; write(x); putchar(\n); }
inline void writel(LL x){ if (x<0) putchar(-),x*=-1; write(x); putchar( ); }
signed main () {
    freopen("key.in","r",stdin);
    freopen("key.out","w",stdout);
    read(n); read(m); read(k);
    for (int i=0;i<n;i++) {
        read(p[i<<1].x); p[i<<1].id=i+1; p[i<<1].to=0;
        read(p[i<<1|1].x); p[i<<1|1].id=i+1; p[i<<1|1].to=1;
    }
    sort(p,p+(n<<1));
    anw=p[0].x+m-p[(n<<1)-1].x;
    for (int i=1;i<(n<<1);i++) {
        if (p[i-1].to==0&&p[i].to==0) a[p[i-1].id]+=p[i].x-p[i-1].x;
        if (p[i-1].to==1&&p[i].to==1) a[p[i].id]+=p[i].x-p[i-1].x;
        if (p[i-1].to==1&&p[i].to==0) anw+=p[i].x-p[i-1].x;
        if (p[i-1].to==0&&p[i].to==1)
         if (p[i-1].id^p[i].id) adds(p[i].id,p[i-1].id,p[i].x-p[i-1].x);
         else a[p[i].id]+=p[i].x-p[i-1].x;
    }
    pp[1]=n; usd[n]=1; 
    for (int i=1;i<=n;i++) {
     if(!pp[i]) cxs=0,pp[i]=find(); 
     usd[pp[i]]=1;
     for (int j=min(k,i);j;j--)  {
         f[i][j]=ma[j-1];
        if (j>1) f[i][j]=max(f[i][j],f[i-1][j-1]+cxs);
        f[i][j]+=a[pp[i]];
        ma[j]=max(ma[j],f[i-1][j]);
     }
     cxs=0;
     eho(pp[i]) 
      if (v^pp[i-1]) pp[i+1]=v,cxs=cost[ii]; 
    }
    writeln(anw+max(ma[k],f[n][k]));
    return 0;
}
View Code

T3:

技术分享图片
#include<bits/stdc++.h>
using namespace std;
#define sight(x) (‘0‘<=x&&x<=‘9‘)
#define eho(x) for(int i=head[x];i;i=net[i])
#define v fall[i]
#define M 4000007
#define inf (1ll<<28)
int x,fall[M],tot,head[M/10],net[M],cost[M],vis[M/10],q[M/10],be,ed,usd[M/10];
inline void read(int &x){
    static char c;
    for (c=getchar();!sight(c);c=getchar());
    for (x=0;sight(c);c=getchar())x=x*10+c-48;
}
void write(int x){if (x<10) {putchar(0+x); return;} write(x/10); putchar(0+x%10);}
inline void writeln(int x){ if (x<0) putchar(-),x*=-1; write(x); putchar(\n); }
inline void writel(int x){ if (x<0) putchar(-),x*=-1; write(x); putchar( ); }
inline void add(int x,int y,int co) {
    fall[++tot]=y; net[tot]=head[x]; head[x]=tot; cost[tot]=co;
}
int spfa(int s,int t) {
    memset(vis,127,sizeof vis);
    q[be=ed=1]=s; usd[s]=1; vis[s]=0;
    while (be<=ed) {
        x=q[be++];
        eho(x) if (vis[x]+cost[i]<vis[v]) {
            vis[v]=vis[x]+cost[i];
            if (!usd[v]) usd[v]=1,q[++ed]=v;
        }
        usd[x]=0;
    }
    return vis[t];
}
int a,b,c,d,e,y,n,L1,L2,R1,R2;
long long Lx,Ly,Rx,Ry;
signed main () {
    freopen("card.in","r",stdin);
    freopen("card.out","w",stdout);
    read(a); read(b); read(c); read(d); read(e);
    read(n);
    for (int i=1;i<=n;i++)  {
        read(x); read(y);
        x--;
        add(x,y,y-x); add(y,x,y-x);
    }
    L1=a; R1=a+b; L2=a+b+c; R2=a+b+c+d;
    Lx=spfa(L1,R1); Rx=spfa(L2,R1);
    Ly=spfa(L1,R2); Ry=spfa(L2,R2);
    if (min(Lx+Ry,Ly+Rx)>inf) {
        cout<<-1<<endl; return 0;
    }
    printf("%lld\n",min(Lx+Ry,Ly+Rx)); 
    return 0; 
}
View Code

 

CXMS ZZ round

标签:car   return   分享图片   har   freopen   printf   --   \n   open   

原文地址:https://www.cnblogs.com/rrsb/p/9033206.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!