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的更多相关文章

  1. Codeforces 585D. Lizard Era: Beginning(meet in the middle)

    一眼题...这个数据范围也太明显了吧... suma1==suma2 && sumb1==sumb2 && sumc1==sumc2 相当于suma1-sumb1==s ...

  2. [codeforces] 585D Lizard Era: Beginning || 双向dfs

    原题 有n(n<=2)个任务和三个人,每次任务给出每个人能得到的值,每次任务选两个人,使n个任务结束后三个人得到的值是一样的.输出每次要派哪两个人,如果不行输出Impossible. n< ...

  3. Codeforces 585D Lizard Era: Beginning | 折半搜索

    参考这个博客 #include<cstdio> #include<algorithm> #include<cstring> #include<map> ...

  4. (中等) CF 585D Lizard Era: Beginning,中途相遇。

    In the game Lizard Era: Beginning the protagonist will travel with three companions: Lynn, Meliana a ...

  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. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

随机推荐

  1. CodeMirror 使用大全

    CodeMirror是一个用于编辑器文本框textarea代码高亮javascript插件,为各种编程语言实现关键字,函数,变量等代码高亮显示,丰富的api和可扩展功能以及多个主题样式,能满足您各种项 ...

  2. VUE2.0 饿了吗视频学习笔记(七-终):compute,循环,flex,display:table

    一.star组件使用到了computed属性 computed相当于属性的一个实时计算,当对象的某个值改变的时候,会进行实时计算. computed: { starType() { return 's ...

  3. ;(function ($, undefined){ })(jQuery); 的使用及说明

    对于很多初学者来说很难明白这表示什么,下边我将为大家介绍其相应的作用. 1.代码最前面的分号,可以防止多个文件压缩合并以为其他文件最后一行语句没加分号,而引起合并后的语法错误. 2.匿名函数(func ...

  4. sql 行变列

    select * from market//查看原来所有数据 //第一种方式 select max(case area when '南京' then num else 0 end) 南京, max(c ...

  5. B - Fuzzy Search (FFT)

    题目链接:https://cn.vjudge.net/contest/281959#problem/B 题目大意:给你n,m,k.然后输入两个字符串,n代表第一个字符串s1,m代表第二个字符串s2,然 ...

  6. keepalived高可用系列~通用基础

    简介:今天咱们来聊聊keepalived一 keepalived 架构 1  标准架构: keepalived+lvs/haproxy+后端 real server(mysql从库,nginx.myc ...

  7. SQL Server 备份还原

    SQL Server支持三种备份方式 完全备份: 差异备份 事务日志备份 一般备份方式为,完全备份/每周,差异备份/每天,事务日志备份/按分钟计,这样可确保备份的高效性和可恢复性. 1. 完全备份 备 ...

  8. SpringBoot2.x使用Dev-tool热部署

    SpringBoot2.x使用Dev-tool热部署 为什么使用热部署? 当修改某些文件内容如配置文件时,我们需要重新启动服务器,比较麻烦,需要一个工具来进行检测是否修改.热加载可以检测到修改的部分, ...

  9. python 数据类型详解

    python数据类型详解 参考网址:http://www.cnblogs.com/linjiqin/p/3608541.html 目录1.字符串2.布尔类型3.整数4.浮点数5.数字6.列表7.元组8 ...

  10. Debian Linux Error “Driver 'pcspkr' is already registered, aborting...”

    问题: Error: Driver ‘pcspkr’ is already registered, aborting… 解决: [root@reistlin.com ~]# echo "bl ...