Codeforces 585D Lizard Era: Beginning | 折半搜索
参考这个博客
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
typedef long long ll;
using namespace std;
map< pair<int,int> , pair<int,int> > mp;
map< pair<int,int> , pair<int,int> > :: iterator it;
int ans=-92345678,n,a[30][4];
ll front,back;
vector <int> v;
void dfs1(int x,int l,int m,int w,int f)
{
if (x>n/2)
{
it=mp.find(make_pair(l-m,w-m));
if (it!=mp.end())
{
if (l>it->second.first)
mp[make_pair(l-m,w-m)]=make_pair(l,f);
}
else
mp[make_pair(l-m,w-m)]=make_pair(l,f);
return ;
}
dfs1(x+1,l+a[x][1],m+a[x][2],w,f*3+0);
dfs1(x+1,l+a[x][1],m,w+a[x][3],f*3+1);
dfs1(x+1,l,m+a[x][2],w+a[x][3],f*3+2);
}
void dfs2(int x,int l,int m,int w,int f)
{
if (x>n)
{
it=mp.find(make_pair(m-l,m-w));
if (it!=mp.end())
{
if (it->second.first+l>ans)
{
ans=it->second.first+l;
front=it->second.second;
back=f;
}
}
return ;
}
dfs2(x+1,l+a[x][1],m+a[x][2],w,f*3+0);
dfs2(x+1,l+a[x][1],m,w+a[x][3],f*3+1);
dfs2(x+1,l,m+a[x][2],w+a[x][3],f*3+2);
}
void print(int x)
{
if (!x) puts("LM");
else if (x==1) puts("LW");
else puts("MW");
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
scanf("%d%d%d",&a[i][1],&a[i][2],&a[i][3]);
}
dfs1(1,0,0,0,0);
dfs2(n/2+1,0,0,0,0);
if (ans>-92345678)
{
for (int i=(n+1)/2;i>=1;i--)
{
v.push_back(back%3);
back/=3;
}
for (int i=n/2;i>=1;i--)
{
v.push_back(front%3);
front/=3;
}
for (int i=v.size()-1;i>=0;i--)
print(v[i]);
}
else puts("Impossible");
return 0;
}
Codeforces 585D Lizard Era: Beginning | 折半搜索的更多相关文章
- Codeforces 585D Lizard Era: Beginning
Lizard Era: Beginning 折半之后搜就完事了, 直接存string字符串卡空间, 随便卡卡空间吧. #include<bits/stdc++.h> #define LL ...
- [codeforces] 585D Lizard Era: Beginning || 双向dfs
原题 有n(n<=2)个任务和三个人,每次任务给出每个人能得到的值,每次任务选两个人,使n个任务结束后三个人得到的值是一样的.输出每次要派哪两个人,如果不行输出Impossible. n< ...
- Codeforces 585D. Lizard Era: Beginning(meet in the middle)
一眼题...这个数据范围也太明显了吧... suma1==suma2 && sumb1==sumb2 && sumc1==sumc2 相当于suma1-sumb1==s ...
- (中等) 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\)个任务结束后三个人得到的值是一样的,且尽量 ...
- Codeforces Round #297 (Div. 2)E. Anya and Cubes 折半搜索
Codeforces Round #297 (Div. 2)E. Anya and Cubes Time Limit: 2 Sec Memory Limit: 512 MBSubmit: xxx ...
随机推荐
- easyui基于 layui.laydate日期扩展组件
本人后端开发码农一个,公司前端忙的一逼,项目使用的是easyui组件,其自带的datebox组件使用起来非常不爽,主要表现在 1.自定义显示格式很麻烦 2.选择年份和月份用户体验也不好 网上有关于和M ...
- 洛谷题解:P1209 【[USACO1.3]修理牛棚 Barn Repair】
原题传送门:https://www.luogu.org/problemnew/show/P1209 首先,这是一道贪心题. 我们先来分析它的贪心策略. 例如,样例: 4 50 18 3 4 6 ...
- BZOJ3884: 上帝与集合的正确用法(欧拉函数 扩展欧拉定理)
Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 3860 Solved: 1751[Submit][Status][Discuss] Descripti ...
- SAP标准导出功能 - 删除默认选定格式
我们经常会使用SAP系统的标准功能导出ALV显示的数据,一般会选择电子表格. 选择电子表格之后,需要选择电子表格的具体格式. 选择格式之后点击确定,会弹出保存对话框. 如果在使用这个功能的时候,选择了 ...
- LeetCode969. 煎饼排序
问题:969. 煎饼排序 给定数组 A,我们可以对其进行煎饼翻转:我们选择一些正整数 k <= A.length,然后反转 A 的前 k 个元素的顺序.我们要执行零次或多次煎饼翻转(按顺序一次接 ...
- Gulp工具
Gulp是一个基于node开发的构建工具. gulp本身是不进行任何构建任务,是通过gulp的一些列插件完成: gulp-less 编译LESS文件: gulp-autoprefix 添加css私 ...
- Orcale(一)
oracle数据库基本语句查询 ORacle-12560:TNS 协议配置器错误 1.服务:1.监听服务未开启 2.服务器未开启 3.环境变量:Oracle_sid = orcl 4.regedit注 ...
- python—— 文件的打开模式和文件对象方法 & os、os.path 模块中关于文件、目录常用的函数使用方法
引用自“鱼c工作室” 文件的打开模式和文件对象方法 : https://fishc.com.cn/forum.php?mod=viewthread&tid=45279&ext ...
- POJ:3276-Face The Right Way(线性反转)
Face The Right Way Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6259 Accepted: 2898 De ...
- JAVA EE配TOMCAT
纯粹就是吧百度教程上的过程走了一遍发现不行综合各种教程配出来了,四张图代表了四个阶段,以后再要配的话直接来这里看.