(中等) CF 585D Lizard Era: Beginning,中途相遇。
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,中途相遇。的更多相关文章
- Codeforces 585D Lizard Era: Beginning
Lizard Era: Beginning 折半之后搜就完事了, 直接存string字符串卡空间, 随便卡卡空间吧. #include<bits/stdc++.h> #define LL ...
- Codeforces 585D. Lizard Era: Beginning(meet in the middle)
一眼题...这个数据范围也太明显了吧... suma1==suma2 && sumb1==sumb2 && sumc1==sumc2 相当于suma1-sumb1==s ...
- [codeforces] 585D Lizard Era: Beginning || 双向dfs
原题 有n(n<=2)个任务和三个人,每次任务给出每个人能得到的值,每次任务选两个人,使n个任务结束后三个人得到的值是一样的.输出每次要派哪两个人,如果不行输出Impossible. n< ...
- Codeforces 585D Lizard Era: Beginning | 折半搜索
参考这个博客 #include<cstdio> #include<algorithm> #include<cstring> #include<map> ...
- 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 ...
- Codeforces 585.D Lizard Era: Beginning
D. Lizard Era: Beginning time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning
折半搜索,先搜索一半的数字,记录第一个人的值,第二个人.第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案. 代码 #include<cstdio> ...
- CF585D Lizard Era: Beginning
嘟嘟嘟 题面我是不会咕的(没有真香):有\(n(n \leqslant 25)\)个任务和三个人,每次任务给出每个人能得到的值,每次任务选两个人,使\(n\)个任务结束后三个人得到的值是一样的,且尽量 ...
- uva 6757 Cup of Cowards(中途相遇法,貌似)
uva 6757 Cup of CowardsCup of Cowards (CoC) is a role playing game that has 5 different characters (M ...
随机推荐
- python--sorted函数
摘自:http://www.cnblogs.com/65702708/archive/2010/09/14/1826362.html 我们需要对List进行排序,Python提供了两个方法对给定的Li ...
- 【Python爬虫实战--1】深入理解urllib;urllib2;requests
摘自:http://1oscar.github.io/blog/2015/07/05/%E6%B7%B1%E5%85%A5%E7%90%86%E8%A7%A3urllib;urllib2;reques ...
- tablehost
返回键的拦截 @Override public boolean dispatchKeyEvent(KeyEvent event) { if (event.getKeyCode() == KeyEven ...
- CREATE SCHEMA
CREATE SCHEMA 创建一个架构,即命名空间,在这个空间中可以进一步定义包含表.视图和权限定义等对象. 语法 CREATE SCHEMA AUTHORIZATION owner [ &l ...
- iOS View 模糊效果(毛玻璃)
iOS View 模糊效果(毛玻璃) 相关资料 http://stackoverflow.com/questions/18404907/using-gpuimage-to-recreate-ios ...
- git 使用系列(二)---- 分支和合并
Branching and Merging The Git feature that really makes it stand apart from nearly every other SCM o ...
- 转 由一次磁盘告警引发的血案:du 和 ls 的区别
如果你完全不明白或者完全明白图片含义, 那么你不用继续往下看了. 否则, 这篇文章也许正是你需要的. 背景 确切地说,不是收到的自动告警短信或者邮件告诉我某机器上的磁盘满了,而是某同学人肉发现该机器写 ...
- idea编译器中maven项目获取路径的方法
资源文件放在哪里? 上 图中的 resources 目录叫资源目录 (main下,与java如果没有请自行创建), 在项目编译后文件会被放到红色的 classes 目录下, 注意如果你的 resour ...
- HTML+CSS Day06 超链接的样式与搭配
1.格式 a:link {} 普通的.未被访问的链接 a:visited {} 用户已访问的链接 a:hover {} 鼠标指针位于链接的上方 a:active{} 链接被点击的时刻 2.常 ...
- 美团,点评,澎湃等APP的启示
事先声明,因个人能力尚浅,文章若有不足之处,望留言指出,也欢迎成为好朋友. 本来想打算写团购类APP的竞品分析,但是发现不管是天天果园这样生鲜APP,还是澎湃这样的新闻资讯APP,思路差不多,都是: ...