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=;
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[][];
int rnum[]; int bbb;
long long lll; void dfs1(int d,Num tn,int b,long long l)
{
if(d>((N+)>>))
{
sta[cou].n=tn;
sta[cou].base=b;
sta[cou++].route=l;
return;
} for(int i=;i<;++i)
dfs1(d+,tn+rem[d][i],b+(i ? rnum[d] : ),(l<<)|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<<(*(N/)))|l;
} return;
} for(int i=;i<;++i)
dfs2(d+,tn+rem[d][i],b+(i ? rnum[d] : ),(l<<)|i);
} void show()
{
int rrr[]; for(int i=;i<N;++i)
{
rrr[i]=lll & ;
lll>>=;
} for(int i=N-;i>=;--i)
if(rrr[i]==) puts("MW");
else if(rrr[i]==) 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=;i<=N;++i)
{
scanf("%d %d %d",&a,&b,&c);
rnum[i]=a;
rem[i][]=Num(b,c);
rem[i][]=Num(-a,c-a);
rem[i][]=Num(b-a,-a);
} cou=;
bbb=-INF;
dfs1(,Num(,),,);
sort(sta,sta+cou,cmp);
cou=unique(sta,sta+cou)-sta;
dfs2((N+)/+,Num(,),,); if(bbb==-INF) puts("Impossible");
else show(); return ;
}

(中等) CF 585D Lizard Era: Beginning,中途相遇。的更多相关文章

  1. Codeforces 585D Lizard Era: Beginning

    Lizard Era: Beginning 折半之后搜就完事了, 直接存string字符串卡空间, 随便卡卡空间吧. #include<bits/stdc++.h> #define LL ...

  2. Codeforces 585D. Lizard Era: Beginning(meet in the middle)

    一眼题...这个数据范围也太明显了吧... suma1==suma2 && sumb1==sumb2 && sumc1==sumc2 相当于suma1-sumb1==s ...

  3. [codeforces] 585D Lizard Era: Beginning || 双向dfs

    原题 有n(n<=2)个任务和三个人,每次任务给出每个人能得到的值,每次任务选两个人,使n个任务结束后三个人得到的值是一样的.输出每次要派哪两个人,如果不行输出Impossible. n< ...

  4. Codeforces 585D Lizard Era: Beginning | 折半搜索

    参考这个博客 #include<cstdio> #include<algorithm> #include<cstring> #include<map> ...

  5. 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/5 ...

  6. Codeforces 585.D Lizard Era: Beginning

    D. Lizard Era: Beginning time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  7. Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning

    折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...

  8. CF585D Lizard Era: Beginning

    嘟嘟嘟 题面我是不会咕的(没有真香):有\(n(n \leqslant 25)\)个任务和三个人,每次任务给出每个人能得到的值,每次任务选两个人,使\(n\)个任务结束后三个人得到的值是一样的,且尽量 ...

  9. uva 6757 Cup of Cowards(中途相遇法,貌似)

    uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...

随机推荐

  1. SSH登录很慢问题的解决方法

    用ssh连其他linux机器,会等待10-30秒才有提示输入密码.严重影响工作效率. 关闭ssh的gssapi认证 用ssh -v user@server 可以看到登录时有如下信息: debug1: ...

  2. AutoMapper 自动映射工具

    先引用对应的DLL. 11.转换匿名对象 结合LINQ映射新的实体类. using System;using System.Collections.Generic;using System.Linq; ...

  3. PatrolRobot(UVa1600)BFS

    PatrolRobot(UVa1600)BFS 珉黻郐距 河吏蝉醉 闵棵黏言 芤她之瞌 褰上稽莨 錾傻奉 郦玫睃芩 摇摇头还没回答魏海洪就抢先回答道:呵呵你们几个别试 蚰镉氡 钬 绦可 ...

  4. Eclipse+EPIC+PadWalker

    来源: http://www.cnblogs.com/itech/archive/2010/02/23/1671676.html http://blog.csdn.net/haoyujie/artic ...

  5. Photoshop 字体

    字体类型: 宋体系列:北宋年间 超粗宋.粗宋,大标宋.小标宋/中宋.宋体 黑体系列:建国初期 (当时写标语,识别度高) 超粗黑 大黑/黑体 中等线/细黑 --广告.画册.宣传册 非正规场合 文字工具( ...

  6. 报表Reporting S而vice是 错误的解决

    Reporting Services 错误 报表服务器无法打开与报表服务器数据库的连接.所有请求和处理都要求与数据库建立连接. (rsReportServerDatabaseUnavailable)获 ...

  7. photoshop 魔术橡皮擦

    魔术棒和橡皮的结合,不用解锁就能抠图

  8. PHP基本类型操作

    //关键字对大小写不敏感echo ('hello world!<br>');ECho ('hello world<br>');eCho ('hello world<br& ...

  9. VC2010编译错误

    1. cannot convert parameter 1 from 'const char [43]' to 'LPCWSTR' 我是看了这个之后解决问题的~ http://blog.163.com ...

  10. 关于jQuery的条件判断问题

    遇到的第一个问题,点击第一行用toggle实现背景的变换,需要在toggle函数里面判断,当下面显示的时候是一个状态,下面不显示的时候是另一个状态,我用了 if($(".check-box& ...