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连试试水的深浅..... ...
随机推荐
- TCP/IP详解 卷1 第十九章 TCP的交互数据流
19.1 引言 成块数据:比如ftp.电子邮件.Usenet新闻 交互数据:Telnet.Rlogin 成块数据的报文段基本上都是满长度(full-size)的,而交互数据小的多(Telnet和Rlo ...
- MSVCR120.dll丢失问题
一.问题:丢失MSVCR120.dll 二.解决方法 到官网下载vcredist_x86.exe安装即可 地址:https://www.microsoft.com/en-us/download/det ...
- Guava Immutable 不可变集合
Immutable是为了创建不可变集合使用,不可变集合在很多情况下能提高系统性能.一般使用 .of()或者.builder()<>().put().build()初始化创建不可变集合
- entity framework 时间操作
).FirstOrDefault(); if (useractiveentity == null) { UserActive userActive = new UserActive(); userAc ...
- JavaScript之Dom操作【删除当前节点】
//最新更新:2017-11-25 //现在可以通过更强大而快捷的方式为所有的HTMLElement元素的Dom操作扩展新的方法[注意事项:处理HTMLElemnt元素时,此法对IE-8无效] //原 ...
- HTML5的学习(二)HTML5标签
3.按功能排列标签 (注:红色为HTML5不支持的,蓝色为HTML5新增的标签元素.) 3.1基本 标签 描述 HTML4 HTML5 <!--...--> 定义注释. √ √ < ...
- RunLoop 原理和核心机制
搞iOS之后一直没有深入研究过RunLoop,非常的惭愧.刚好前一阵子负责性能优化项目,需要利用RunLoop做性能优化和性能检测,趁着这个机会深入研究了RunLoop的原理和特性. RunLoop的 ...
- python将图片转换为Framebuffer裸数据格式(终端显示图片)【转】
转自:https://www.cnblogs.com/zqb-all/p/6107905.html 要在ubuntu终端显示图片或者在板子的LCD显示图片,Framebuffer是一个简单易用的接口, ...
- php 日期格式转换万能公式
思路用strtotime转换时间的字符串 $t='2017-03-09 02:30'; echo(date('Y-m-d H-i', strtotime($t)));
- weblogic实时监控开发
参考api文档 https://docs.oracle.com/cd/E13222_01/wls/docs90/wlsmbeanref/core/index.html https://docs.ora ...