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连试试水的深浅..... ...
随机推荐
- IDA Pro使用技巧
DA Pro基本简介 IDA加载完程序后,3个立即可见的窗口分别为IDA-View,Named,和消息输出窗口(output Window). IDA图形视图会有执行流,Yes箭头默认为绿色,No箭头 ...
- 虚拟机centos7系统下安装hadoop ha和yarn ha(详细)
一:基础环境准备 (一):虚拟机新建五个centos7系统(复制文件夹的方式) (二):角色分配 (三)按照角色分配表配置 (1)更改主机ip(自行查找),如果只是个人搭建玩一玩,可选择安装cento ...
- The connection to adb is down, and a severe error has occured(Android模拟器端口被占用)
相信不少同学和我一样遇到这个问题,有时候搞的还要重启电脑,那究竟是什么原因导致的呢,很明显,你的端口被占用了,那下面给出终极解决方案 一.首先描述症状,如下图 二.出现问题了,首先确定你的sdk目录是 ...
- 2017CCPC秦皇岛 C题Crusaders Quest&&ZOJ3983【模拟+STL】
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3983 题意: 给定9个血槽,有三种物品,每次可以把连续相同的物品抵消 ...
- VMware xp系统联网
1.
- 【网络编程3】网络编程基础-arp请求(局域网主机扫描)
ARP协议 ARP(Add ress Resolution Protocol)地址解析协议位于数据链路层,是根据IP地址获取MAC地址的一个协议. ARP 查看指令 arp -a 显示所有接口的当前A ...
- python 历险记(二)— python 的面向对象
目录 前言 类和对象 如何定义和实例化类? 如何定义和使用属性? 什么是方法? 静态方法和普通方法 构造函数该怎么写? str 方法怎么写? 多态是什么? 继承性和 java 是一样的吗? 父类和子类 ...
- MR数据生成工具指向目录
mrDataTidy_SaveTwoDays.jar 原始路径 :D:\太原MR数据\一天数据整理 目标路径 : D:\MR现场数据整理\保存两天_整理后数据 例如 当前时间:2017-5-17 10 ...
- UML和模式应用5:细化阶段(7)---从需求到设计迭代进化
1.前言 迭代开发中,每次迭代都会发生从以需求或分析为主要焦点到以设计和实现为主要焦点的转变 分析和面向对象的分析重点关注学习做正确的事,理解案例重要目标,规则和约束 设计工作强调正确的做事,熟练设计 ...
- Bootstrap3.0学习第四轮(排版)
详情请查看http://aehyok.com/Blog/Detail/10.html 个人网站地址:aehyok.com QQ 技术群号:206058845,验证码为:aehyok 本文文章链接:ht ...