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. ice使用过程遇到的问题

    1 设置代理超时时间ice_timeout ICE的每个连接都有两个超时时间:ice_timeout.ice_connectiontimeout,分别对应消息的超时时间和连接建立    的超时时间,可 ...

  2. shell:crontab

    crontab */1 * * * * (cd /home/q/system/project; /usr/bin/lockf -t 0 /tmp/discuz_bbs_audit.lock /usr/ ...

  3. Go-file

    两个包具有文件操作的相关方法,一个是os,一个是syscall,其中os中的相关方法是对syscall相关方法的封装,推荐使用os中的相关方法.文件的打开文件的第一步操作实际上是创建,但是由于文件的打 ...

  4. 学习PHP函数:preg_match_all

    <?php $str = '10.10.10.10, 10.10.10.11'; preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', ...

  5. iptables查看、添加、删除规则

    1.查看iptables -nvL –line-number -L 查看当前表的所有规则,默认查看的是filter表,如果要查看NAT表,可以加上-t NAT参数-n 不对ip地址进行反查,加上这个参 ...

  6. python socketserver实现客户端多并发

    直接看代码 server #!/usr/bin/env python # -*- coding:utf-8 -*- import socketserver import subprocess clas ...

  7. Js根据class名替换html标签内容 ,在某标签前后添加内容

    function getClass(obj, attr) { var aArray = [];//定义一个新的空数组 var i = 0; var aAll = document.getElement ...

  8. FreeRTOS中断优先级配置(重要)

    FreeRTOS中断优先级配置(重要) 本章节为大家讲解FreeRTOS中断优先级配置,此章节非常重要,初学者经常在这里犯迷糊.对于初学者来说,本章节务必要整明白.12.1 NVIC基础知识12.2  ...

  9. C语言根据函数名调用对应的函数

    通过函数指针定义,调用时加上参数 struct Command { const char *name; const char *desc; // return -1 to force monitor ...

  10. How to write a probeContentType() and Usage?

    Files.probeContentType() is an instance of FileTypeDetector class's abstract method String FileTypeD ...