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连试试水的深浅..... ...
随机推荐
- webuploader 百度上传,一个页面多个上传按钮
需求:列表里每条数据需加文件上传 html: <div> <ul class="SR_wrap_pic"></ul> <button ty ...
- 数据库 之 E-R设计感想
1.实体与实体之间的关系,在许多情况下,可以将其实体化为实体(弱实体),例如:员工租赁宿舍,可以将租赁弱实体化为实体(具有唯一主键ID) 2.一些具有特征的关系可以(弱)实体化为实体 3.实体里面可以 ...
- 让 IE9 以下的浏览器支持 Media Queries
1. 如何让 IE9 以下的浏览器支持 css3 的media query 需要用到的 min-width/max-width 属性 css3 的媒体查询 IE 浏览器的支持程度是从 IE9开始支持, ...
- JavaScript学习 - 基础(六) - DOM基础操作
DOM: DOM定义了访问HTML 和XML 文档的标准:1.核心DOM 针对结构化文档的标准模型2.XMK DOM 针对XML文档的标准模型3.HTML DOM 针对HTML文档的标准模型 DOM节 ...
- 根据href给当前导航添加样式
var href = window.location.href.split('/')[window.location.href.split('/').length-1].substr(0,20); i ...
- sql 中的null值
1.包含null的表达式都为空 select salary*12+nvl(bonus,0) nvl是虑空函数 2. null值永远!=null select * from emp where bo ...
- 关于形如--error LNK2005: xxx 已经在 msvcrtd.lib ( MSVCR90D.dll ) 中定义--的问题分析解决
转自:http://hi.baidu.com/qinfengxiaoyue/item/ff262ccfb53b4c2ba0b50a89 引自:http://blog.csdn.net/sptoor/a ...
- 根据txt中的文件名将文件复制到目标文件夹中
功能如标题,之所以这么做是有的时候文件数目较多,一个一个复制太复杂了,代码如下: # -*- coding:utf-8 -*- #2018_03_18 #实现功能:根据文件名字将对应的文件复制到目标地 ...
- python标准库之secrets
secrets secrets是python3.6加入到标准库的,使用secrets模块,可以生成适用于处理机密信息(如密码,帐户身份验证,安全令牌)的加密强随机数. 导入 import secret ...
- mysql系列二、mysql内部执行过程
向MySQL发送一个请求的时候,MySQL到底做了什么 客户端发送一条查询给服务器. 服务器先检查查询缓存,如果命中了缓存,则立刻返回存储在缓存中的结果.否则进入下一阶段. 服务器端进行SQL解析.预 ...