zoukankan      html  css  js  c++  java
  • (中等) CF 585D Lizard Era: Beginning,中途相遇。

      In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has nmandatory quests. To perform each of them, you need to take exactly two companions.

    The attitude of each of the companions to the hero is an integer. Initially, the attitude of each of them to the hero of neutral and equal to 0. As the hero completes quests, he makes actions that change the attitude of the companions, whom he took to perform this task, in positive or negative direction.

    Tell us what companions the hero needs to choose to make their attitude equal after completing all the quests. If this can be done in several ways, choose the one in which the value of resulting attitude is greatest possible.

      题目就是问能不能找到一组序列然后符合条件。。。

      一眼看去就是中途相遇,n只有25,两个dfs就行了。。。

      第一次用SBT维护的,然后1996ms险过,第二次改成sort,498ms,不得不说真是快啊。。。

    代码如下:

    // ━━━━━━神兽出没━━━━━━
    //      ┏┓       ┏┓
    //     ┏┛┻━━━━━━━┛┻┓
    //     ┃           ┃
    //     ┃     ━     ┃
    //     ████━████   ┃
    //     ┃           ┃
    //     ┃    ┻      ┃
    //     ┃           ┃
    //     ┗━┓       ┏━┛
    //       ┃       ┃
    //       ┃       ┃
    //       ┃       ┗━━━┓
    //       ┃           ┣┓
    //       ┃           ┏┛
    //       ┗┓┓┏━━━━━┳┓┏┛
    //        ┃┫┫     ┃┫┫
    //        ┗┻┛     ┗┻┛
    //
    // ━━━━━━感觉萌萌哒━━━━━━
    
    // Author        : WhyWhy
    // Created Time  : 2015年10月13日 星期二 17时27分11秒
    // File Name     : F.cpp
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    
    using namespace std;
    
    const int MaxN=2000005;
    const int INF=0x3f3f3f3f;
    
    struct Num
    {
        int a,b;
    
        Num() {}
        Num(int x,int y):a(x),b(y) {}
    
        bool operator < (const Num & y) const
        {
            return a==y.a ? b<y.b : a<y.a;
        }
    
        bool operator > (const Num & y) const
        {
            return a==y.a ? b>y.b : a>y.a;
        }
    
        bool operator == (const Num & y) const
        {
            return a==y.a && b==y.b;
        }
    
        Num operator + (const Num & y) const
        {
            return Num(a+y.a,b+y.b);
        }
    };
    
    struct State
    {
        Num n;
        int base;
        long long route;
    
        bool operator < (const State &b) const
        {
            return n<b.n;
        }
    
        bool operator == (const State &b) const
        {
            return n==b.n;
        }
    };
    
    bool cmp(const State &a,const State &b)
    {
        return a.n==b.n ? a.base>b.base : a.n<b.n;
    }
    
    State sta[MaxN];
    int cou;
    
    int N;
    Num rem[30][3];
    int rnum[30];
    
    int bbb;
    long long lll;
    
    void dfs1(int d,Num tn,int b,long long l)
    {
        if(d>((N+1)>>1))
        {
            sta[cou].n=tn;
            sta[cou].base=b;
            sta[cou++].route=l;
            return;
        }
    
        for(int i=0;i<3;++i)
            dfs1(d+1,tn+rem[d][i],b+(i ? rnum[d] : 0),(l<<2)|i);
    }
    
    void dfs2(int d,Num tn,int b,long long l)
    {
        if(d>N)
        {
            State ts;
            ts.n.a=-tn.a;
            ts.n.b=-tn.b;
    
            int p=lower_bound(sta,sta+cou,ts)-sta;
    
            if(p<cou && sta[p]==ts && sta[p].base+b>bbb)
            {
                bbb=sta[p].base+b;
                lll=(sta[p].route<<(2*(N/2)))|l;
            }
    
            return;
        }
    
        for(int i=0;i<3;++i)
            dfs2(d+1,tn+rem[d][i],b+(i ? rnum[d] : 0),(l<<2)|i);
    }
    
    void show()
    {
        int rrr[30];
    
        for(int i=0;i<N;++i)
        {
            rrr[i]=lll & 3;
            lll>>=2;
        }
    
        for(int i=N-1;i>=0;--i)
            if(rrr[i]==0) puts("MW");
            else if(rrr[i]==1) puts("LW");
            else puts("LM");
    }
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    
        int a,b,c;
    
        scanf("%d",&N);
        for(int i=1;i<=N;++i)
        {
            scanf("%d %d %d",&a,&b,&c);
            rnum[i]=a;
            rem[i][0]=Num(b,c);
            rem[i][1]=Num(-a,c-a);
            rem[i][2]=Num(b-a,-a);
        }
    
        cou=0;
        bbb=-INF;
        dfs1(1,Num(0,0),0,0);
        sort(sta,sta+cou,cmp);
        cou=unique(sta,sta+cou)-sta;
        dfs2((N+1)/2+1,Num(0,0),0,0);
    
        if(bbb==-INF) puts("Impossible");
        else show();
        
        return 0;
    }
    View Code
  • 相关阅读:
    【OpenCV学习】多通道矩阵的赋值和取值
    使用BackGroundWorker在多线程中访问Winform控件,当不是创建这个控件的线程访问控件时,把线程调整到是创建这个控件的线程去控制。,代码为红色的
    创建Windows服务程序实现定时操作
    新建和发布Windows服务的几个常见问题
    关于程序卡时解决方案
    c#中使用多线程访问winform中控件的若干问题 解决线程间操作无效: 从不是创建控件的线程访问它
    winform安装项目、安装包的制作、部署
    C# winform 使用进度条(两种形式)
    WinForm如何控制ShowDialog()的返回值,并且可以判断是否会弹出主窗体
    收藏几个好用的webservice
  • 原文地址:https://www.cnblogs.com/whywhy/p/4875570.html
Copyright © 2011-2022 走看看