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. C# Memcached缓存

    net/c#分布式缓存系统Memcached简介与实践--非常好 缘起: 在数据驱动的web开发中,经常要重复从数据库中取出相同的数据,这种重复极大的增加了数据库负载.缓存是解决这个问题的好办法.但是 ...

  2. BFS and Queue

    BFS (Bridth First Search) can be implemented by a queue. Procedure is like this: (Q is Queue) 1, Put ...

  3. viewpager处理(二):设置当前item时,让viewpager不出现滑动动画

    我们在使用viewpager.setCurrentItem(position);的时候,viewpager出现滑动动画,如何去掉这个动画呢? 可以用viewpager.setCurrentItem(p ...

  4. three dot

    http://stackoverflow.com/questions/28031603/what-do-three-dots-mean-in-go-command-line-invocations

  5. apt-key adv

    gpg --recv-keys KEY-ID                gpg --armor --export KEY-ID | sudo apt-key add - http://m.blog ...

  6. OpenGL 图形管道(graphics pipeline)过程

    1.总结:Graphics pipeline 主要分为两部分工作 把3D坐标转换成2D坐标 把2D坐标转换成真实的有颜色的像素 2.下图就是一个顶点数据经过几个步骤后转化成显示在屏幕上像素的过程(一般 ...

  7. icon在页面中的使用

    https://icomoon.io/app/#/select 1.上传.svg新图标 2.选中那个小图标,点底部导航的生成字体. 3.然后命名,下载. 4.下载下来的内容只有这两处是必须要用的. 5 ...

  8. Windows下MySQL分步安装图解及问题总结

    MySQL是一个出色的开源数据库,在易用性和性能方面都有相当不错的表现.就作者发帖为止, MySQL官方发布的所有版本中(4.1/5.0/5.1/6.0),推荐使用稳定的MySQL5.0版本(商用). ...

  9. isinstance使用方法

    #!/usr/bin/python2.7    def displayNumType(num):    print num, 'is',    if isinstance(num,(int, long ...

  10. ARC属性中还能使用assign,copy,retain这些关键字吗

    http://blog.sina.com.cn/s/blog_6531b9b80101c6cr.html      很早以前比较弱,网上不知道哪里看了篇博文,留下了ARC属性中不能使用retain关键 ...