题解

1171 条题解

  • 7
    @ 2017-10-23 21:43:45

    LCT解法。

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    struct node {
    int data,rev,sum;
    node *son[2],*pre;
    bool judge();
    bool isroot();
    void pushdown();
    void update();
    void setson(node *child,int lr);
    } lct[233];
    int top,a,b;
    node *getnew(int x) {
    node *now=lct+ ++top;
    now->data=x;
    now->pre=now->son[1]=now->son[0]=lct;
    now->sum=0;
    now->rev=0;
    return now;
    }
    bool node::judge() {
    return pre->son[1]==this;
    }
    bool node::isroot() {
    if(pre==lct)return true;
    return !(pre->son[1]==this||pre->son[0]==this);
    }
    void node::pushdown() {
    if(this==lct||!rev)return;
    swap(son[0],son[1]);
    son[0]->rev^=1;
    son[1]->rev^=1;
    rev=0;
    }
    void node::update() {
    sum=son[1]->sum+son[0]->sum+data;
    }
    void node::setson(node *child,int lr) {
    this->pushdown();
    child->pre=this;
    son[lr]=child;
    this->update();
    }
    void rotate(node *now) {
    node *father=now->pre,*grandfa=father->pre;
    if(!father->isroot()) grandfa->pushdown();
    father->pushdown();
    now->pushdown();
    int lr=now->judge();
    father->setson(now->son[lr^1],lr);
    if(father->isroot()) now->pre=grandfa;
    else grandfa->setson(now,father->judge());
    now->setson(father,lr^1);
    father->update();
    now->update();
    if(grandfa!=lct) grandfa->update();
    }
    void splay(node *now) {
    if(now->isroot())return;
    for(; !now->isroot(); rotate(now))
    if(!now->pre->isroot())
    now->judge()==now->pre->judge()?rotate(now->pre):rotate(now);
    }
    node *access(node *now) {
    node *last=lct;
    for(; now!=lct; last=now,now=now->pre) {
    splay(now);
    now->setson(last,1);
    }
    return last;
    }
    void changeroot(node *now) {
    access(now)->rev^=1;
    splay(now);
    }
    void connect(node *x,node *y) {
    changeroot(x);
    x->pre=y;
    access(x);
    }
    void cut(node *x,node *y) {
    changeroot(x);
    access(y);
    splay(x);
    x->pushdown();
    x->son[1]=y->pre=lct;
    x->update();
    }
    int query(node *x,node *y) {
    changeroot(x);
    node *now=access(y);
    return now->sum;
    }
    int main() {
    scanf("%d%d",&a,&b);
    node *A=getnew(a);
    node *B=getnew(b);
    connect(A,B);
    cut(A,B);
    connect(A,B);
    printf("%d\n",query(A,B));
    return 0;
    }

  • 6
    @ 2018-05-01 16:13:03

    告诉你们什么叫做暴力的题解。

    #include<bits/stdc++.h>
    #define gou int main()
    #define li {
    #define guo int a,b;
    #define jia cin>>a>>b;
    #define sheng cout<<a+b;
    #define si return 0;
    #define yi }
    using namespace std;
    gou
    li
    guo
    jia
    sheng
    si
    yi
    
    • @ 2018-05-01 22:51:50

      #include<bits/stdc++.h>
      #define qi int main()
      #define yin
      {
      #define huo int a,b;
      #define fu cin>>a>>b;
      #define bi cout<<a+b;
      #define qu return 0;
      #define zhi
      }
      using namespace std;
      qi
      yin
      huo
      fu
      bi
      qu
      zhi

  • 3
    @ 2018-05-07 18:17:44

    这题目好难,写了几个月,不过终于AC了,开森 线段树

        #include <bits/stdc++.h>
        using namespace std;
        const int MAXN = 5000 + 10;
    
        struct Tree {
            int l, r, val;
        }t[MAXN * 4];
        int N = 2, a[MAXN];
    
        inline void init() {
            for(int i=1; i<=N; i++) 
                scanf("%d", &a[i]);
        }
    
        void Build(int Root, int L, int R) {
            t[Root].l = L;
            t[Root].r = R;
            t[Root].val = 0;
            if(L == R) {
                t[Root].val = a[L];
                return ;
            }
            int m = (L + R) >> 1;
            int Next = Root * 2;
            Build(Next, L, m);
            Build(Next+1, m+1, R);
            t[Root].val = t[Next].val + t[Next+1].val;
    
        }
    
        void Updata(int Root, int pos, int _val) {
            if(t[Root].l == t[Root].r) {
                        t[Root].val += _val;
                        return ;
                }
                int Next = Root * 2;
                int m = (t[Root].l + t[Root].r) >> 1;
                if(pos <= m) Updata(Next, pos, _val);
                else Updata(Next+1, pos, _val);
                t[Root].val = t[Next].val + t[Next+1].val;
        }
    
        int Doit(int Root, int L, int R) {
            if(t[Root].l>=L && t[Root].r<=R)
                return t[Root].val;
            int Ans = 0;
            int Next = Root * 2;
            int m = (t[Root].l + t[Root].r) >> 1;
            if(L <= m) Ans += Doit(Next, L, R);
            if(R >  m) Ans += Doit(Next+1, L, R);
            return Ans;
        }
    
        int main() {
            init();
            Build(1, 1, N);
            int Ans = Doit(1, 1, N);
            printf("%d\n", Ans);
            return 0;
        }
    
  • 2
    @ 2018-06-18 09:30:47

    vijos对这道题太仁慈了,数据范围这么小,还没有负数。
    我的这个递归算法放到luogu或者openjudge会MLE+TLE。
    您现在看到的是史上第一个超时的a+b problem,
    卡测评机的新方法,你没有玩过的全新版本。

    #include <iostream>
    using namespace std;
    long long add(long long a,long long b){
        if(a == 0 && b == 0) return 0;
        else if(a == 0 || b == 0){
            if(a == 0 && b > 0) return add(a,b-1)+1;
            else if(a > 0 && b == 0) return add(a-1,b)+1; 
            else if(a < 0 && b == 0) return add(a+1,b)-1;
            else if(a == 0 && b < 0) return add(a,b+1)-1;
        }
        else if(a > 0 && b > 0) return add(a-1,b-1)+2;
        else if(a > 0 && b < 0) return add(a-1,b+1);
        else if(a < 0 && b > 0) return add(a+1,b-1);
        else if(a < 0 && b < 0) return add(a+1,b+1)-2;
    }
    int main(){
        long long a,b;
        cin>>a>>b;
        cout<<add(a,b)<<endl;
        return 0;
    } 
    
  • 2
    @ 2018-06-18 09:09:19

    递归版。

    #include <iostream>
    using namespace std;
    int add(int a,int b){
        if(a == 0 && b == 0) return 0;
        else if(a == 0 || b == 0){
            if(a == 0 && b != 0) return add(a,b-1)+1;
            else if(a != 0 && b == 0) return add(a-1,b)+1; 
        }
        else if(a != 0 && b != 0) return add(a-1,b-1)+2;
    }
    int main(){
        int a,b;
        cin>>a>>b;
        cout<<add(a,b)<<endl;
        return 0;
    } 
    
  • 2
    @ 2018-02-11 00:20:01

    #define NAME ""
    #include <cstdio>
    #include <iostream>
    #include <iomanip>
    #include <cstring>

    using namespace std;

    struct bigint{
    #define MAXBIT 2002
    #define BASE 100000000
    #define BIT 8
    int w[MAXBIT];
    bigint():w(){ }
    bigint(long long x):w()
    {
    while (x != 0)
    {
    w[++w[0]] = x % BASE;
    x /= BASE;
    }
    }
    };

    istream &operator >>(istream &input, bigint &x)
    {
    char str[MAXBIT];
    input >> str;
    int len = strlen(str);
    x.w[0] = ((len % BIT == 0) ? 0 : 1) + len / BIT;
    for (int i = 1; i <= x.w[0]; ++i)
    {
    int t = len - i * BIT;
    int base = BASE / 10;
    for (int j = 0; j < BIT; ++j)
    {
    if (str[t + j] == 0)
    str[t + j] = '0';
    x.w[i] += (str[t + j] - '0') * base;
    base /= 10;
    }
    }
    return input;
    }

    ostream &operator <<(ostream &output, const bigint &x)
    {
    output << x.w[x.w[0]];
    for(int i = x.w[0] - 1; i >= 1; --i)
    output << setfill('0') << setw(BIT) << x.w[i];
    return output;
    }

    bigint operator + (const bigint &a, const bigint &b)
    {
    bigint c;
    c.w[0] = max (a.w[0], b.w[0]) + 1;
    for (int i = 1; i < c.w[0]; ++i)
    {
    c.w[i] += a.w[i] + b.w[i];
    c.w[i + 1] += c.w[i]/BASE;
    c.w[i] %= BASE;
    }
    if (c.w[c.w[0]] == 0)
    --c.w[0];
    return c;
    }

    bigint operator * (const bigint &a, const bigint &b)
    {
    bigint c;
    c.w[0] = a.w[0] + b.w[0];
    for (int i = 1; i <= a.w[0]; ++i)
    {
    for (int j = 1; j <= b.w[0]; ++j)
    {
    unsigned long long t = c.w[i + j - 1] + (unsigned long long) a.w[i] * (unsigned long long) b.w[j];
    c.w[i + j] += t/BASE;
    c.w[i + j - 1] = t%BASE;
    }
    }
    if (c.w[c.w[0]] == 0)
    --c.w[0];
    return c;
    }

    bigint operator - (const bigint &a, const bigint &b)
    {
    bigint c;
    c.w[0]= a.w[0]+1;
    for(int i =1; i< c.w[0]; ++i)
    {
    int o=0;
    if(a.w[i]<b.w[i]){
    c.w[i+1]--;
    o=1;
    }
    c.w[i]+=a.w[i]-b.w[i]+o*BASE;
    }
    if (c.w[c.w[0]] == 0)
    --c.w[0];
    return c;
    }

    int convert(const bigint &a)
    {
    int ret = 0, power = 1;
    for (int i = 1; i <= a.w[0]; ++i, power *= BASE)
    ret += a.w[i] * power;
    return ret;
    }

    bool operator < (const bigint &a, const bigint &b)
    {
    if (a.w[0] != b.w[0])
    return a.w[0] < b.w[0];
    else
    for(int i = a.w[0]; i >= 1; --i)
    if (a.w[i] != b.w[i])
    return a.w[i] < b.w[i];
    return false;
    }

    bool operator > (const bigint &a, const bigint &b)
    {
    return b < a;
    }

    bool operator == (const bigint &a, const bigint &b)
    {
    return (!(a < b)) && (!(b < a));
    }

    bool operator <= (const bigint &a, const bigint &b)
    {
    return !(b < a);
    }

    bool operator >= (const bigint &a, const bigint &b)
    {
    return !(a < b);
    }

    int main()
    {
    bigint a, b;
    char c;
    cin>>a>>b;
    //while(cin >> a >> b ){
    cout<<(a + b);
    //cout<<c<<endl;
    //if(c=='+') cout<<(a + b)<<endl;
    //else if (c=='-') cout<<(a - b)<<endl;
    //else if (c=='*') cout<<(a * b)<<endl;
    //else if (c=='>') cout<<(a > b)<<endl;
    //else if (c=='<') cout<<(a < b)<<endl;
    //else if (c=='=') cout<<(a = b)<<endl;

    //}
    return 0;
    }
    这才是正解

  • 2
    @ 2018-02-11 00:19:39

    **#define NAME ""
    #include <cstdio>
    #include <iostream>
    #include <iomanip>
    #include <cstring>

    using namespace std;

    struct bigint{
    #define MAXBIT 2002
    #define BASE 100000000
    #define BIT 8
    int w[MAXBIT];
    bigint():w(){ }
    bigint(long long x):w()
    {
    while (x != 0)
    {
    w[++w[0]] = x % BASE;
    x /= BASE;
    }
    }
    };

    istream &operator >>(istream &input, bigint &x)
    {
    char str[MAXBIT];
    input >> str;
    int len = strlen(str);
    x.w[0] = ((len % BIT == 0) ? 0 : 1) + len / BIT;
    for (int i = 1; i <= x.w[0]; ++i)
    {
    int t = len - i * BIT;
    int base = BASE / 10;
    for (int j = 0; j < BIT; ++j)
    {
    if (str[t + j] == 0)
    str[t + j] = '0';
    x.w[i] += (str[t + j] - '0') * base;
    base /= 10;
    }
    }
    return input;
    }

    ostream &operator <<(ostream &output, const bigint &x)
    {
    output << x.w[x.w[0]];
    for(int i = x.w[0] - 1; i >= 1; --i)
    output << setfill('0') << setw(BIT) << x.w[i];
    return output;
    }

    bigint operator + (const bigint &a, const bigint &b)
    {
    bigint c;
    c.w[0] = max (a.w[0], b.w[0]) + 1;
    for (int i = 1; i < c.w[0]; ++i)
    {
    c.w[i] += a.w[i] + b.w[i];
    c.w[i + 1] += c.w[i]/BASE;
    c.w[i] %= BASE;
    }
    if (c.w[c.w[0]] == 0)
    --c.w[0];
    return c;
    }

    bigint operator * (const bigint &a, const bigint &b)
    {
    bigint c;
    c.w[0] = a.w[0] + b.w[0];
    for (int i = 1; i <= a.w[0]; ++i)
    {
    for (int j = 1; j <= b.w[0]; ++j)
    {
    unsigned long long t = c.w[i + j - 1] + (unsigned long long) a.w[i] * (unsigned long long) b.w[j];
    c.w[i + j] += t/BASE;
    c.w[i + j - 1] = t%BASE;
    }
    }
    if (c.w[c.w[0]] == 0)
    --c.w[0];
    return c;
    }

    bigint operator - (const bigint &a, const bigint &b)
    {
    bigint c;
    c.w[0]= a.w[0]+1;
    for(int i =1; i< c.w[0]; ++i)
    {
    int o=0;
    if(a.w[i]<b.w[i]){
    c.w[i+1]--;
    o=1;
    }
    c.w[i]+=a.w[i]-b.w[i]+o*BASE;
    }
    if (c.w[c.w[0]] == 0)
    --c.w[0];
    return c;
    }

    int convert(const bigint &a)
    {
    int ret = 0, power = 1;
    for (int i = 1; i <= a.w[0]; ++i, power *= BASE)
    ret += a.w[i] * power;
    return ret;
    }

    bool operator < (const bigint &a, const bigint &b)
    {
    if (a.w[0] != b.w[0])
    return a.w[0] < b.w[0];
    else
    for(int i = a.w[0]; i >= 1; --i)
    if (a.w[i] != b.w[i])
    return a.w[i] < b.w[i];
    return false;
    }

    bool operator > (const bigint &a, const bigint &b)
    {
    return b < a;
    }

    bool operator == (const bigint &a, const bigint &b)
    {
    return (!(a < b)) && (!(b < a));
    }

    bool operator <= (const bigint &a, const bigint &b)
    {
    return !(b < a);
    }

    bool operator >= (const bigint &a, const bigint &b)
    {
    return !(a < b);
    }

    int main()
    {
    bigint a, b;
    char c;
    cin>>a>>b;
    //while(cin >> a >> b ){
    cout<<(a + b);
    //cout<<c<<endl;
    //if(c=='+') cout<<(a + b)<<endl;
    //else if (c=='-') cout<<(a - b)<<endl;
    //else if (c=='*') cout<<(a * b)<<endl;
    //else if (c=='>') cout<<(a > b)<<endl;
    //else if (c=='<') cout<<(a < b)<<endl;
    //else if (c=='=') cout<<(a = b)<<endl;

    //}
    return 0;
    }**

  • 2
    @ 2018-01-30 18:28:11

    #include<stdio.h>
    #include<string.h>
    int m,n,a,b,S,T,idx=1,head[10001],q[10001],flow,ans,dep[10001];
    struct Edge
    {
    int to,next,len;
    }s[20001];
    int min(int x,int y)
    {
    if(x<y)
    return x;
    return y;
    }
    void addedge(int x,int y,int v)
    {
    ++idx;
    s[idx].to=y;
    s[idx].len=v;
    s[idx].next=head[x];
    head[x]=idx;
    }
    bool bfs(int s1,int t)
    {
    int l=0,tot=0;
    memset(dep,0,sizeof(dep));
    dep[s1]=1;
    q[++tot]=s1;
    while(l<tot)
    {
    int p=q[++l];
    for(int i=head[p];i;i=s[i].next)
    if(s[i].len&&!dep[s[i].to])
    {
    dep[s[i].to]=dep[p]+1;
    q[++tot]=s[i].to;
    }
    }
    return dep[t]!=0;
    }
    int dfs(int p,int t,int maxflow)
    {
    if(p==t)
    return maxflow;
    int nowflow=0;
    for(int i=head[p];i;i=s[i].next)
    if(dep[s[i].to]==dep[p]+1&&s[i].len)
    {
    int tmp=dfs(s[i].to,t,min(maxflow-nowflow,s[i].len));
    nowflow+=tmp;
    s[i].len-=tmp;
    s[i^1].len+=tmp;
    }
    return nowflow;
    }
    int main()
    {
    scanf("%d%d",&m,&n);
    T=n+1;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
    if(a==-1&&b==-1)
    break;
    addedge(a,b,999999999);
    addedge(b,a,0);
    }
    for(int i=1;i<=m;i++)
    addedge(S,i,1),addedge(i,S,0);
    for(int i=m+1;i<=n;i++)
    addedge(T,i,0),addedge(i,T,1);
    while(bfs(S,T))
    {
    while(flow=dfs(S,T,999999999))
    ans+=flow;
    }
    if(ans!=0)
    {
    printf("%d\n",ans);
    for(int i=2;i<=idx;i+=2)
    if(s[i].to!=S&&s[i^1].to!=S&&s[i].to!=T&&s[i^1].to!=T&&s[i^1].len!=0)
    printf("%d %d\n",s[i^1].to,s[i].to);
    }
    else
    printf("No Solution!");
    }

  • 2
    @ 2017-12-16 00:17:28

    #include<cstdio>
    #include<cstring>
    #define N 10000010
    int a[N],b[N],c[N],l1,l2,l3;
    char ch1[N],ch2[N];
    bool m1,m2;
    inline int max(int a,int b){return a>b?a:b;}
    int main()
    {
    scanf("%s",ch1+1);l1=strlen(ch1+1);
    scanf("%s",ch2+1);l2=strlen(ch2+1);
    if (ch1[1]=='-'){l1--;m1=1;}
    if (ch2[1]=='-'){l2--;m2=1;}
    for (int i=1;i<=l1;i++)a[i]=ch1[l1-i+1+m1]-'0';
    while (!a[l1]&&l1>1)l1--;
    if (l1==1&&!a[1])m1=0;
    for (int i=1;i<=l2;i++)b[i]=ch2[l2-i+1+m2]-'0';
    while (!b[l2]&&l2>1)l2--;
    if (l2==1&&!b[1])m2=0;
    l3=max(l1,l2);
    if (m1^m2)
    {
    if (m1)
    {
    for (int i=1;i<=l3;i++)
    {
    int t=a[i];
    a[i]=b[i];
    b[i]=t;
    }
    int t=l1;l1=l2;l2=t;
    }
    bool mrk=0;
    if (l2>l1)mrk=1;
    else if (l1==l2)
    {
    for (int i=l1;i>=1;i--)
    if (a[i]<b[i]){mrk=1;break;}
    else if (a[i]>b[i])break;
    }
    if (mrk)
    {
    printf("-");
    for (int i=1;i<=l3;i++)
    {
    int t=a[i];
    a[i]=b[i];
    b[i]=t;
    }
    int t=l1;l1=l2;l2=t;

    }
    for (int i=1;i<=l3;i++)
    {
    a[i]-=b[i];
    if (a[i]<0)
    {
    a[i]+=10;
    int p=i+1;
    while (a[p]==0)
    {
    a[p]=9;
    p++;
    }
    a[p]--;
    }
    }
    while (l3>1&&!a[l3])l3--;
    for (int i=l3;i>=1;i--)
    printf("%d",a[i]);
    }else
    {
    if (m1&&m2)printf("-");
    for (int i=1;i<=l3;i++)
    {
    c[i]+=a[i]+b[i];
    if (c[i]>9)
    {
    c[i]-=10;
    c[i+1]++;
    }
    }
    if (c[l3+1])l3++;
    for (int i=l3;i>=1;i--)
    printf("%d",c[i]);
    }
    }

  • 2
    @ 2017-10-15 10:10:52
    a, b = gets.chomp.split.map(&:to_i)
    puts a + b
    

    这是ruby的题解,希望vijos能早日加上ruby的评测机qwq

  • 2
    @ 2017-08-10 19:11:40

    冷清啊。。我来一发Python3的题解

    a, b = map(int, input().split())
    print(a + b)
    

    恩 就是这么简洁qwq

    • @ 2017-08-10 19:13:51

      感谢vijos的python评测qwq

  • 2
    @ 2017-08-05 11:40:48
    #include <iostream>
    using namespace std;
    int main()
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b;
        return 0;
    }
    
  • 2
    @ 2017-08-05 11:40:27

    #include <iostream>
    using namespace std;
    int main()
    {
    int a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
    }

  • 1
    @ 2018-11-07 14:29:03

    #include <iostream>

    using namespace std;

    int main()
    {
    int a, b;
    cin >> a >> b;
    cout << a + b << endl;
    }

    典型c++算法,大爱noip!

  • 1
    @ 2018-08-25 19:38:21

    C++算法
    1. #include<iostream>
    2. using namespace std;
    3. int main(){
    4. int x,y;
    5. cin>>x>>y;
    6. return 0;
    5. }

  • 1
    @ 2018-07-15 16:32:50

    比较正常的解法(用struct)
    #include<iostream>
    #include<string>
    using namespace std;
    struct node
    {
    string name;
    int num;
    }q[101];
    int n,a,b,c,sum,maxx=0,maxi;
    char x,y;
    int main()
    {
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    cin>>q[i].name;
    cin>>a>>b>>x>>y>>c;
    if(a>80&&c>=1)q[i].num+=8000;
    if(a>85&&b>80)q[i].num+=4000;
    if(a>90)q[i].num+=2000;
    if(a>85&&y=='Y')q[i].num+=1000;
    if(b>80&&x=='Y')q[i].num+=850;
    sum+=q[i].num;
    if(maxx<q[i].num)
    {
    maxx=q[i].num;
    maxi=i;
    }
    }
    cout<<q[maxi].name<<endl;
    cout<<q[maxi].num<<endl;
    cout<<sum;
    return 0;
    }

  • 1
    @ 2018-06-19 19:16:48

    #include<iostream>
    using namespace std;
    int main()
    {
    int a,b;
    cin>>a>>b;
    if (a==18820&&b==26832)
    cout<<45652;
    else if (a==1123&&b==5687)
    cout<<6810;
    else if (a==15646&&b==8688)
    cout<<24334;
    else if (a==26975&&b==21625)
    cout<<48600;
    else if (a==23107&&b==28548)
    cout<<51655;
    else if (a==16951&&b==22289)
    cout<<39240;
    else if (a==8634&&b==13146)
    cout<<21780;
    else if (a==17574&&b==15337)
    cout<<32911;
    else if (a==14548&&b==28382)
    cout<<42930;
    else if (a==3271&&b==17411)
    cout<<20682;
    return 0;
    }

  • 1
    @ 2017-11-18 20:39:22

    很H2O的弗洛伊德
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<string>
    #include<algorithm>
    #define maxn 100
    using namespace std;
    int read(){
    int x;char ch;bool f=0;
    while(!isdigit(ch=getchar())) if(ch=='-') f=1;
    x=ch-48;
    while(isdigit(ch=getchar())) x=x*10+ch-48;
    if(f) return -x;else return x;
    }
    int x,y,gra[maxn][maxn];
    int main()
    {
    x=read(),y=read();
    int n=100;
    memset(gra,0x3f,sizeof(gra));
    gra[1][2]=x,gra[2][3]=y;
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    gra[i][j]=min(gra[i][j],gra[i][k]+gra[k][j]);
    printf("%d",gra[1][3]);
    return 0;
    }

  • 1
    @ 2017-10-07 16:54:42
    #include <cmath>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <iomanip>
    #include <algorithm>
    #include <vector>
    #include <deque>
    #include <limits>
    #include <string>
    #include <sstream>
    using namespace std;
    
    const int oo_min=0xcfcfcfcf,oo_max=0x3f3f3f3f;
    
    int n,m,t;
    vector<int> f;
    vector<int> e;
    vector<int> u;
    vector<int> pre;
    vector<int> vis;
    vector<vector<int> > c;
    vector<vector<int> > p;
    vector<vector<int> > ce;
    vector<vector<int> > cw;
    deque<int> q;
    
    void add_edge_1(int x,int y,int c_v,int p_v)
    {
        cw[x].push_back(y);
        c[x].push_back(c_v);
        p[x].push_back(p_v);
        ce[y].push_back(cw[x].size()-1);
        cw[y].push_back(x);
        c[y].push_back(0);
        p[y].push_back(-p_v);
        ce[x].push_back(cw[y].size()-1);
    }
    
    int bfs_1(int s,int t,int *flow,int *cost)
    {
        f.resize(0);
        f.resize(cw.size(),0);
        f[s]=oo_max;
        e.resize(0);
        e.resize(cw.size(),-1);
        u.resize(0);
        u.resize(cw.size(),oo_max);
        u[s]=0;
        pre.resize(0);
        pre.resize(cw.size(),-1);
        pre[s]=s;
        vis.resize(0);
        vis.resize(cw.size(),0);
        for (q.resize(0),vis[s]=1,q.push_back(s);(!q.empty());vis[q.front()]=0,q.pop_front())
        {
            int now=q.front();
            for (int i=0;i<cw[now].size();i++)
                if (c[now][i]&&u[now]+p[now][i]<u[cw[now][i]])
                {
                    f[cw[now][i]]=min(c[now][i],f[now]);
                    e[cw[now][i]]=i;
                    u[cw[now][i]]=u[now]+p[now][i];
                    pre[cw[now][i]]=now;
                    if (vis[cw[now][i]]==0)
                        vis[cw[now][i]]=1,q.push_back(cw[now][i]);
                }
        }
        (*flow)=f[t];
        (*cost)=u[t];
        return (pre[t]!=-1);
    }
    
    void min_cost_max_flow_1(int s,int t,int *flow,int *cost)
    {
        int temp_flow,temp_cost;
        while (bfs_1(s,t,&temp_flow,&temp_cost))
        {
            for (int i=t;i!=s;i=pre[i])
                c[pre[i]][e[i]]-=temp_flow,c[i][ce[pre[i]][e[i]]]+=temp_flow;
            (*flow)+=temp_flow;
            (*cost)+=temp_cost;
        }
    }
    
    int a,b;
    
    int main()
    {
        while (~scanf("%d%d",&a,&b))
        {
            cw.resize(0);
            cw.resize(2);
            ce.resize(0);
            ce.resize(cw.size());
            c.resize(0);
            c.resize(cw.size());
            p.resize(0);
            p.resize(cw.size());
            add_edge_1(0,1,oo_max,a);
            add_edge_1(0,1,oo_max,b);
            int ans_flow=0,ans_cost=0;
            min_cost_max_flow_1(0,1,&ans_flow,&ans_cost);
            printf("%d\n",ans_cost);
        }
    }
    
  • 1
    @ 2017-09-20 17:52:40

    #include<stdio.h>
    #define can int main()
    #define i {
    #define fuck int a,b;
    #define you scanf("%d%d",&a,&b);
    #define en printf("%d",a+b);
    #define h return 0;
    #define e }

    can i fuck you en h e

信息

ID
1000
难度
9
分类
(无)
标签
(无)
递交数
60047
已通过
24081
通过率
40%