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 ...
随机推荐
- 微信小程序清除默认样式
1.清除button的默认样式 button::after{border:none;}input{outline:none;border:none;list-style: none;}
- avalon ms-repeat avalon1
工作原因要用到avalon二次开发, 但是看了下以前的avalon版本是1,现在大多数都是2版本了吧,,所以很多文档不好找,但是大多数还是好用的 ms-repeat 循环当前赋值的, ms-repea ...
- Linux文件服务器实战(匿名用户)
一.进程与线程 二.vsftp服务器 1.文件传输协议(file transfer protocol,FTP) 基于该协议ftp客户端和服务端实现文件共享,上传下载文件 FTP基于TCP协议生成一个虚 ...
- LINUX操作系统知识:进程与线程详解
当一个程序开始执行后,在开始执行到执行完毕退出这段时间内,它在内存中的部分就叫称作一个进程. Linux 是一个多任务的操作系统,也就是说,在同一时间内,可以有多个进程同时执行.我们大家常用的单CPU ...
- 如何在创建hive表格的python代码中导入外部文件
业务场景大概是这样的,我要对用户博文进行分词(这个步骤可以看这篇文章如何在hive调用python的时候使用第三方不存在的库-how to use external python library in ...
- gcc常用语法
1. gcc -E source_file.c-E,只执行到预编译.直接输出预编译结果. 2. gcc -S source_file.c -S,只执行到源代码到汇编代码的转换,输出汇编代码. 3. g ...
- SpringMVC---springMVC配置文件(springweb.xml)简介
再web.xml中设置HTTP请求的中央调度处理器DispatcherServlet时,会指定SpringMVC配置文件,这里取名springweb.xml是因设置DispatcherServlet时 ...
- Android 自定义光标样式
今天自定义光标,自己切图,不过怎么切都是很宽.不是一个很细的条.我用ps花了一个像素的直线,放上去还是不行.后来在网上找到方法,那就是用shape.不得不说,shape真的是太吊了. 给EditTex ...
- Django的Field(字段)
字段 1.models.AutoField 自增列 = int(11) 如果没有的话,默认会生成一个名称为 id 的列,如果要显示的自定义一个自增列,必须将给列设置为主键 primary_key=Tr ...
- myeclipse中项目名有红叉,但项目中文件没有报错的解决办法
导入了别人的项目,各种jar包都放好后,path也都build好了,项目也能正常启动,但是就是项目名有红叉,这是为什么呢? 网上有人说Java build path中的jar包missing了,这是一 ...