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[],b[],c[];
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+)
{
pair<int,long long> temp;
temp = H[pair<int,int>(A-B,B-C)];
if(temp.second == )
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+,sta<<|,A,B+b[step],C+c[step]);
dfs1(step+,sta<<|,A+a[step],B,C+c[step]);
dfs1(step+,sta<<|,A+a[step],B+b[step],C);
}
void dfs2(int step,long long sta,int A,int B,int C)
{
if(step==n+)
{
pair<int,long long> temp = H[pair<int,int>(B-A,C-B)];
if(temp.second==)return;
ans = max(ans,pair<int,long long>(A+temp.first,temp.second<<(n-mid<<)|sta));
return;
}
dfs2(step+,sta<<|,A,B+b[step],C+c[step]);
dfs2(step+,sta<<|,A+a[step],B,C+c[step]);
dfs2(step+,sta<<|,A+a[step],B+b[step],C);
}
int main()
{
ans.first = -;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d%d%d",&a[i],&b[i],&c[i]);
mid = (n+)/;
dfs1(,,,,);
dfs2(mid+,,,,);
if(ans.first == -)return puts("Impossible");
vector<int> Ans;
for(int i=;i<=n;i++)
{
Ans.push_back(ans.second&);
ans.second>>=;
}
for(int i=Ans.size()-;i>=;i--)
{
if(Ans[i]==)
cout<<"LM"<<endl;
else if(Ans[i]==)
cout<<"LW"<<endl;
else
cout<<"MW"<<endl;
} }
Codeforces Round #325 (Div. 2) F. Lizard Era: Beginning meet in the mid的更多相关文章
- Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning
折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)
题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)
题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...
随机推荐
- Android开发之IP拨号器原理
IP拨号器,使用了Android的广播接收者(BroadCastReceiver),在广播中把已保存的ip号码放在拨打电话号码的前面(getResultData()),然后把修改后的号码设置到广播中( ...
- C++中巧妙的位运算
位运算要多想到与预算和异或运算,并常常将两个数对应位上相同和不同分开处理 一.x&(x-1)消除x二进制中最右边的一个1. 这个比较厉害,比如统计某个 二.与和异或的巧妙结合的思想 与运算可以 ...
- ubuntu设置ip和dns
装完ubuntu 第一件事情就是连上网,换个源,进行更新操作,但前提条件是要配好ip和dns. 下面把自己配置的过程记录下来,权且当作一份备份,以便不时之需. 一.配置ip ub ...
- codeforces 401D (数位DP)
思路:很明显的数位dp,设dp[i][j] 表示选取数字的状态为i,模m等于j的数的个数,那么最后的答案就是dp[(1<<n)-1][0].状态转移方程就是,dp[i|(1<< ...
- selenium+testNG+Ant
好几天没写了,抽时间写下,也好有个总结: 1.selenium+testNG+Ant (1)ant 是构建工具 他的作用就是运行你配置好的东西 而tentng.xml你可以认为他是管理test的一个配 ...
- 内省与JavaBean
概述 JavaBean代表一类特殊的Java类,这种类主要用来存储和传递属性信息,JavaBean中的方法主要用于设置和获取这些私有属性,他们有一定的命名规则,我们可以把它们想象为一个侧重属性信息的类 ...
- “Clean Code” 读书笔记序
最近开始研读 Robert C.Martin 的 “Clean Code”,为了巩固学习,会把每一章的笔记整理到博客中.而这篇博文作为一个索引和总结,会陆续加入各章的笔记链接,以及全部读完后的心得体会 ...
- 2015上海网络赛 A Puzzled Elena
题意:给定一棵树,求这个节点的所有子树中包括他本身与它互质的节点的个数. 解题思路:题利用dfs序+容斥原理+前缀和性质解决.题目中要求每个结点,和多少个它的子结点互素.如果每次为了求一个点去跑一遍d ...
- UVALIVE 3026 Period
题意:给你一个字符串,问第i位前是否有循环节,若存在,则循环节是多少? 思路:考察失配函数f[i]的意义.只要i%(i-f[i])==0,则循环节长度为i/(i-f[i]).字符在[0,f[i]],[ ...
- FFmpeg YUV视频序列编码为视频
上一篇已经写了如何配置好开发环境,这次就先小试牛刀,来个视频的编码.搞视频处理的朋友肯定比较熟悉YUV视频序列,很多测试库提供的视频数据都是YUV视频序列,我们这里就用用YUV视频序列来做视频.关于Y ...