Codeforces 585D Lizard Era: Beginning
折半之后搜就完事了, 直接存string字符串卡空间, 随便卡卡空间吧。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std; const int N = ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-; int n, L[N], M[N], W[N];
vector<int> vc1, vc2; struct Node {
int L, M, W;
char s[][];
};
vector<Node> tmp;
map<pair<PII,int>, int> Map; Node t, ans1, ans2; void dfs(int x) {
if(x == SZ(vc1)) {
int who = SZ(tmp);
tmp.push_back(t);
int mn = min(t.L, min(t.M, t.W));
auto it = Map.find(mk(mk(t.L-mn, t.M-mn), t.W-mn));
if(it == Map.end() || tmp[it->se].L < tmp[who].L)
Map[mk(mk(t.L-mn, t.M-mn), t.W-mn)] = who;
return;
}
t.L += L[vc1[x]]; t.M += M[vc1[x]]; t.s[x][] = 'L', t.s[x][] = 'M';
dfs(x + );
t.L -= L[vc1[x]]; t.M -= M[vc1[x]]; t.L += L[vc1[x]]; t.W += W[vc1[x]]; t.s[x][] = 'L', t.s[x][] = 'W';
dfs(x + );
t.L -= L[vc1[x]]; t.W -= W[vc1[x]]; t.M += M[vc1[x]]; t.W += W[vc1[x]]; t.s[x][] = 'M', t.s[x][] = 'W';
dfs(x + );
t.M -= M[vc1[x]]; t.W -= W[vc1[x]];
} void dfs2(int x) {
if(x == SZ(vc2)) {
int mn = min(t.L, min(t.M, t.W));
int mx = max(t.L-mn, max(t.M-mn, t.W-mn));
auto it = Map.find(mk(mk(mx-t.L+mn, mx-t.M+mn), mx-t.W+mn));
if(it == Map.end()) return;
int id = it->se;
if(t.L + tmp[id].L > ans1.L + ans2.L) {
ans1 = tmp[id];
ans2 = t;
}
return;
}
t.L += L[vc2[x]]; t.M += M[vc2[x]]; t.s[x][] = 'L', t.s[x][] = 'M';
dfs2(x + );
t.L -= L[vc2[x]]; t.M -= M[vc2[x]]; t.L += L[vc2[x]]; t.W += W[vc2[x]]; t.s[x][] = 'L', t.s[x][] = 'W';
dfs2(x + );
t.L -= L[vc2[x]]; t.W -= W[vc2[x]]; t.M += M[vc2[x]]; t.W += W[vc2[x]]; t.s[x][] = 'M', t.s[x][] = 'W';
dfs2(x + );
t.M -= M[vc2[x]]; t.W -= W[vc2[x]];
} int main() {
cin >> n;
for(int i = ; i < n; i++)
cin >> L[i] >> M[i] >> W[i];
if(n == ) {
if(!L[] && !M[]) puts("LM");
else if(!L[] && !W[]) puts("LW");
else if(!M[] && !W[]) puts("MW");
else puts("Impossible");
return ;
}
int c = n >> ;
for(int i = ; i < c; i++) vc1.push_back(i);
for(int i = c; i < n; i++) vc2.push_back(i); ans1.L = -inf; ans2.L = -inf;
dfs();
dfs2(); if(ans1.L <= -inf) {
puts("Impossible");
return ;
}
for(int i = ; i < c; i++) cout << ans1.s[i][] << ans1.s[i][] << "\n";
for(int i = ; i < n - c; i++) cout << ans2.s[i][] << ans2.s[i][] << "\n";
return ;
} /*
*/
Codeforces 585D Lizard Era: Beginning的更多相关文章
- 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> ...
- (中等) CF 585D Lizard Era: Beginning,中途相遇。
In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana a ...
- 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\)个任务结束后三个人得到的值是一样的,且尽量 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
随机推荐
- JAVA泛型中的类型擦除及为什么不支持泛型数组
一,数组的协变性(covariant array type)及集合的非协变性 设有Circle类和Square类继承自Shape类. 关于数组的协变性,看代码: public static doubl ...
- js加减法运算多出很多小数点
链接:http://www.jb51.net/article/73043.htm 解决方法:解决这种问题两种方法,第一种就是利用JavaScript 的toFixed(n) 方法,直接获取N 位小数, ...
- python技巧 python2中的除法结果为0
在python2中执行除法操作如果结果小于1就会返回0 如下面的例子: >>>81/82 0 如果你需要返回"正确的结果 ",有两种方法: 在脚本中引入from ...
- 【通信】JDK中的URLConnection参数详解
JDK中的URLConnection参数详解 来自:http://www.blogjava.net/supercrsky/articles/247449.html 针对JDK中的URLConnecti ...
- adb环境变量配置
针对win10系统: 搜索“高级系统设置”,点击“环境变量”按钮: 找到“path”双击: 双击“path”,在弹出的环境变量列表中新建,填入adb的文件路径 检查配置是否成功,运行命令adb,出现如 ...
- mysql 案例~ 主从复制转化为级联复制
一 需求 mysql 主从复制切换成级联复制二 核心思想 1 开启级联复制 2 确定postion点场景 A->B A-C 三 切换步骤 1 先确定好B为级联复制库 2 B添加log_upd ...
- Caffe源码阅读(1) 全连接层
Caffe源码阅读(1) 全连接层 发表于 2014-09-15 | 今天看全连接层的实现.主要看的是https://github.com/BVLC/caffe/blob/master/src ...
- spring session使用小记
在并发量大的WEB系统中,Session一般不使用容器Session,而通常使用Redis作为Session的存储.如果为了保持Servlet规范中的Session接口继续可用,往往需要重新实现Ses ...
- 【转】每天一个linux命令(1):ls命令
ls命令是linux下最常用的命令.ls命令就是list的缩写,缺省下ls用来打印出当前目录的清单.如果ls指定其他目录,那么就会显示指定目录里的文件及文件夹清单. 通过ls命令不仅可以查看linux ...
- CAS 策略已被 .NET Framework 弃用
背景 本来想这里有啥写的,就算了吧.突然看到dev了,我的天啊,这个.net大神,坑了多少开发人员了.功能太强大,以至于后来很长时间我都不知道jquery.当时为了操作dev,为了实现一个功能,都把官 ...