zoukankan      html  css  js  c++  java
  • Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid

    F. Lizard Era: Beginning

    Time Limit: 1 Sec  

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/586/problem/F

    Description

    In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana and Worrigan. Overall the game has n mandatory 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.

    Input

    The first line contains positive integer n (1 ≤ n ≤ 25) — the number of important tasks.

    Next n lines contain the descriptions of the tasks — the i-th line contains three integers li, mi, wi — the values by which the attitude of Lynn, Meliana and Worrigan respectively will change towards the hero if the hero takes them on the i-th task. All the numbers in the input are integers and do not exceed 107 in absolute value.

    ​​,Ci​​,即此题的初始分值、每分钟减少的分值、dxy做这道题需要花费的时间。

    Output

    If there is no solution, print in the first line "Impossible".

    Otherwise, print n lines, two characters is each line — in the i-th line print the first letters of the companions' names that hero should take to complete the i-th task ('L' for Lynn, 'M' for Meliana, 'W' for Worrigan). Print the letters in any order, if there are multiple solutions, print any of them.

    Sample Input

    7
    0 8 9
    5 9 -2
    6 -8 -7
    9 4 5
    -4 -9 9
    -4 5 2
    -6 8 -7

    Sample Output

    LM
    MW
    LM
    LW
    MW
    LM
    LW

    HINT

    题意

    有n个任务,有三个人

    每次任务都必须派两个人出去,每个任务都会使得人涨能力值,不同人涨的不一样

    然后问你有没有一种方案可以使得所有人最后的能力值都一样

    如果有多种方案,请输出可以最后使得能力值最大的一种方案

    题解:

    meet in the mid,状态存三个量就好了A,A-B,B-C,然后就可以瞎搜了,注意最后要输出方案,所以就直接把中间的过程都状压一下就行了

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<map>
    #include<vector>
    using namespace std;
    
    int mid,n;
    int a[30],b[30],c[30];
    map<pair<int,int> ,pair<int,long long> >H;
    pair<int,long long> ans;
    void dfs1(int step,long long sta,int A,int B,int C)
    {
        if(step==mid+1)
        {
            pair<int,long long> temp;
            temp = H[pair<int,int>(A-B,B-C)];
            if(temp.second == 0)
                H[pair<int,int>(A-B,B-C)] = pair<int,long long>(A,sta);
            else
                H[pair<int,int>(A-B,B-C)] = max(temp,pair<int,long long>(A,sta));
            return;
        }
        dfs1(step+1,sta<<2|1,A,B+b[step],C+c[step]);
        dfs1(step+1,sta<<2|2,A+a[step],B,C+c[step]);
        dfs1(step+1,sta<<2|3,A+a[step],B+b[step],C);
    }
    void dfs2(int step,long long sta,int A,int B,int C)
    {
        if(step==n+1)
        {
            pair<int,long long> temp = H[pair<int,int>(B-A,C-B)];
            if(temp.second==0)return;
            ans = max(ans,pair<int,long long>(A+temp.first,temp.second<<(n-mid<<1)|sta));
            return;
        }
        dfs2(step+1,sta<<2|1,A,B+b[step],C+c[step]);
        dfs2(step+1,sta<<2|2,A+a[step],B,C+c[step]);
        dfs2(step+1,sta<<2|3,A+a[step],B+b[step],C);
    }
    int main()
    {
        ans.first = -99999999;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%d%d%d",&a[i],&b[i],&c[i]);
        mid = (n+1)/2;
        dfs1(1,0,0,0,0);
        dfs2(mid+1,0,0,0,0);
        if(ans.first == -99999999)return puts("Impossible");
        vector<int> Ans;
        for(int i=1;i<=n;i++)
        {
            Ans.push_back(ans.second&3);
            ans.second>>=2;
        }
        for(int i=Ans.size()-1;i>=0;i--)
        {
            if(Ans[i]==3)
                cout<<"LM"<<endl;
            else if(Ans[i]==2)
                cout<<"LW"<<endl;
            else
                cout<<"MW"<<endl;
        }
    
    }
  • 相关阅读:
    页面跳转
    获取gridview 某列的值
    C#日期格式化的几种处理方法(转)
    asp.net 退出 按钮
    asp.net控件大全(一)
    导出Excel
    DropDownList的二级联动 (SqlDataSource实现和SQL 绑定实现)
    asp.net控件大全(二)
    如何让Gridview在没有数据的时候显示表头(asp.net)
    自定义日期格式
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4874212.html
Copyright © 2011-2022 走看看