Lizard Era: Beginning

折半之后搜就完事了, 直接存string字符串卡空间, 随便卡卡空间吧。

  1. #include<bits/stdc++.h>
  2. #define LL long long
  3. #define fi first
  4. #define se second
  5. #define mk make_pair
  6. #define PLL pair<LL, LL>
  7. #define PLI pair<LL, int>
  8. #define PII pair<int, int>
  9. #define SZ(x) ((int)x.size())
  10. #define ull unsigned long long
  11. using namespace std;
  12.  
  13. const int N = ;
  14. const int inf = 0x3f3f3f3f;
  15. const LL INF = 0x3f3f3f3f3f3f3f3f;
  16. const int mod = 1e9 + ;
  17. const double eps = 1e-;
  18.  
  19. int n, L[N], M[N], W[N];
  20. vector<int> vc1, vc2;
  21.  
  22. struct Node {
  23. int L, M, W;
  24. char s[][];
  25. };
  26. vector<Node> tmp;
  27. map<pair<PII,int>, int> Map;
  28.  
  29. Node t, ans1, ans2;
  30.  
  31. void dfs(int x) {
  32. if(x == SZ(vc1)) {
  33. int who = SZ(tmp);
  34. tmp.push_back(t);
  35. int mn = min(t.L, min(t.M, t.W));
  36. auto it = Map.find(mk(mk(t.L-mn, t.M-mn), t.W-mn));
  37. if(it == Map.end() || tmp[it->se].L < tmp[who].L)
  38. Map[mk(mk(t.L-mn, t.M-mn), t.W-mn)] = who;
  39. return;
  40. }
  41. t.L += L[vc1[x]]; t.M += M[vc1[x]]; t.s[x][] = 'L', t.s[x][] = 'M';
  42. dfs(x + );
  43. t.L -= L[vc1[x]]; t.M -= M[vc1[x]];
  44.  
  45. t.L += L[vc1[x]]; t.W += W[vc1[x]]; t.s[x][] = 'L', t.s[x][] = 'W';
  46. dfs(x + );
  47. t.L -= L[vc1[x]]; t.W -= W[vc1[x]];
  48.  
  49. t.M += M[vc1[x]]; t.W += W[vc1[x]]; t.s[x][] = 'M', t.s[x][] = 'W';
  50. dfs(x + );
  51. t.M -= M[vc1[x]]; t.W -= W[vc1[x]];
  52. }
  53.  
  54. void dfs2(int x) {
  55. if(x == SZ(vc2)) {
  56. int mn = min(t.L, min(t.M, t.W));
  57. int mx = max(t.L-mn, max(t.M-mn, t.W-mn));
  58. auto it = Map.find(mk(mk(mx-t.L+mn, mx-t.M+mn), mx-t.W+mn));
  59. if(it == Map.end()) return;
  60. int id = it->se;
  61. if(t.L + tmp[id].L > ans1.L + ans2.L) {
  62. ans1 = tmp[id];
  63. ans2 = t;
  64. }
  65. return;
  66. }
  67. t.L += L[vc2[x]]; t.M += M[vc2[x]]; t.s[x][] = 'L', t.s[x][] = 'M';
  68. dfs2(x + );
  69. t.L -= L[vc2[x]]; t.M -= M[vc2[x]];
  70.  
  71. t.L += L[vc2[x]]; t.W += W[vc2[x]]; t.s[x][] = 'L', t.s[x][] = 'W';
  72. dfs2(x + );
  73. t.L -= L[vc2[x]]; t.W -= W[vc2[x]];
  74.  
  75. t.M += M[vc2[x]]; t.W += W[vc2[x]]; t.s[x][] = 'M', t.s[x][] = 'W';
  76. dfs2(x + );
  77. t.M -= M[vc2[x]]; t.W -= W[vc2[x]];
  78. }
  79.  
  80. int main() {
  81. cin >> n;
  82. for(int i = ; i < n; i++)
  83. cin >> L[i] >> M[i] >> W[i];
  84. if(n == ) {
  85. if(!L[] && !M[]) puts("LM");
  86. else if(!L[] && !W[]) puts("LW");
  87. else if(!M[] && !W[]) puts("MW");
  88. else puts("Impossible");
  89. return ;
  90. }
  91. int c = n >> ;
  92. for(int i = ; i < c; i++) vc1.push_back(i);
  93. for(int i = c; i < n; i++) vc2.push_back(i);
  94.  
  95. ans1.L = -inf; ans2.L = -inf;
  96. dfs();
  97. dfs2();
  98.  
  99. if(ans1.L <= -inf) {
  100. puts("Impossible");
  101. return ;
  102. }
  103. for(int i = ; i < c; i++) cout << ans1.s[i][] << ans1.s[i][] << "\n";
  104. for(int i = ; i < n - c; i++) cout << ans2.s[i][] << ans2.s[i][] << "\n";
  105. return ;
  106. }
  107.  
  108. /*
  109. */

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. TCP/IP详解 卷1 第十九章 TCP的交互数据流

    19.1 引言 成块数据:比如ftp.电子邮件.Usenet新闻 交互数据:Telnet.Rlogin 成块数据的报文段基本上都是满长度(full-size)的,而交互数据小的多(Telnet和Rlo ...

  2. MSVCR120.dll丢失问题

    一.问题:丢失MSVCR120.dll 二.解决方法 到官网下载vcredist_x86.exe安装即可 地址:https://www.microsoft.com/en-us/download/det ...

  3. Guava Immutable 不可变集合

    Immutable是为了创建不可变集合使用,不可变集合在很多情况下能提高系统性能.一般使用 .of()或者.builder()<>().put().build()初始化创建不可变集合

  4. entity framework 时间操作

    ).FirstOrDefault(); if (useractiveentity == null) { UserActive userActive = new UserActive(); userAc ...

  5. JavaScript之Dom操作【删除当前节点】

    //最新更新:2017-11-25 //现在可以通过更强大而快捷的方式为所有的HTMLElement元素的Dom操作扩展新的方法[注意事项:处理HTMLElemnt元素时,此法对IE-8无效] //原 ...

  6. HTML5的学习(二)HTML5标签

    3.按功能排列标签 (注:红色为HTML5不支持的,蓝色为HTML5新增的标签元素.)   3.1基本 标签 描述 HTML4 HTML5 <!--...--> 定义注释. √ √ < ...

  7. RunLoop 原理和核心机制

    搞iOS之后一直没有深入研究过RunLoop,非常的惭愧.刚好前一阵子负责性能优化项目,需要利用RunLoop做性能优化和性能检测,趁着这个机会深入研究了RunLoop的原理和特性. RunLoop的 ...

  8. python将图片转换为Framebuffer裸数据格式(终端显示图片)【转】

    转自:https://www.cnblogs.com/zqb-all/p/6107905.html 要在ubuntu终端显示图片或者在板子的LCD显示图片,Framebuffer是一个简单易用的接口, ...

  9. php 日期格式转换万能公式

    思路用strtotime转换时间的字符串 $t='2017-03-09 02:30'; echo(date('Y-m-d H-i', strtotime($t)));

  10. weblogic实时监控开发

    参考api文档 https://docs.oracle.com/cd/E13222_01/wls/docs90/wlsmbeanref/core/index.html https://docs.ora ...