Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning
折半搜索,先搜索一半的数字,记录第一个人的值,第二个人、第三个人和第一个人的差值,开个map哈希存一下,然后另一半搜完直接根据差值查找前一半的答案。
代码
#include<cstdio>
#include<map>
#define ll long long
#define N 100
using namespace std;
map<long long,int> ma,Ma;
char str[];
int n,i,a[N],b[N],c[N],Ans,A1,A2,ans[N];
void dfs(ll x,ll y,ll z,int d,int k)
{
if (d>n/)
{
long long tmp=(y-x)*+(z-x);
if ((ma.find(tmp)==ma.end())||(x>ma[tmp]))
{
ma[tmp]=x;
Ma[tmp]=k;
}
return;
}
dfs(x+a[d],y+b[d],z,d+,k*);
dfs(x,y+b[d],z+c[d],d+,k*+);
dfs(x+a[d],y,z+c[d],d+,k*+);
}
void Dfs(ll x,ll y,ll z,int d,int k)
{
if (d>n)
{
long long tmp=(x-y)*+(x-z);
if (ma.find(tmp)!=ma.end())
{
if (ma[tmp]+x>Ans)
{
Ans=ma[tmp]+x;
A1=Ma[tmp];
A2=k;
}
}
return;
}
Dfs(x+a[d],y+b[d],z,d+,k*);
Dfs(x,y+b[d],z+c[d],d+,k*+);
Dfs(x+a[d],y,z+c[d],d+,k*+);
}
int main()
{
scanf("%d",&n);
Ans=-0x37373737;int q=;
for (i=;i<=n;i++)
{
scanf("%d%d%d",&a[i],&b[i],&c[i]);
}
/*
for (i=1;i<=n;i++)
{
scanf("%s",str);
if (str[0]=='L') q+=a[i];
}
printf("%d\n",q);
*/
dfs(,,,,);
Dfs(,,,n/+,); if (Ans==-0x37373737)
printf("Impossible");
else
{
//printf("%d\n",Ans);
for (i=n;i>n/;i--)
{
ans[i]=A2%;
A2=A2/;
}
for (i=n/;i>=;i--)
{
ans[i]=A1%;
A1=A1/;
}
for (i=;i<=n;i++)
if (ans[i]==)
printf("LM\n");
else
if (ans[i]==)
printf("MW\n");
else
if (ans[i]==)
printf("LW\n");
}
}
Codeforces Round #325 (Div. 1) D. Lizard Era: Beginning的更多相关文章
- 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 Round #325 (Div. 2) D. Phillip and Trains BFS
D. Phillip and Trains Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/ ...
- Codeforces Round #325 (Div. 2) C. Gennady the Dentist 暴力
C. Gennady the Dentist Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586 ...
- Codeforces Round #325 (Div. 2) A. Alena's Schedule 水题
A. Alena's Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/pr ...
- Codeforces Round #325 (Div. 2) B. Laurenty and Shop 前缀和
B. Laurenty and Shop Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/586/p ...
- Codeforces Round #325 (Div. 2) Phillip and Trains dp
原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...
- Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟
原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...
- Codeforces Round #325 (Div. 2) Alena's Schedule 模拟
原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...
- Codeforces Round #325 (Div. 2) D bfs
D. Phillip and Trains time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- 面向对象之struct
struct PointStruct { int pointx = 1; int pointy = 2; public PointStruct(int x, int y) { this.pointx ...
- Redis学习笔记(1)-Key
package cn.com; import java.text.ParseException; import java.util.List; import java.util.Set; import ...
- 学习之js绑定事件
由于ie中绑定事件的bug,所以产生了用原生的实践操作来模拟事件绑定的方法,跟着李炎恢学的一招. function addEvent(obj, type, fn){ if(obj.addEventLi ...
- php--求几个数中的最小值
<?phpecho min(2, 3, 1, 6, 7); // 1echo min(array(2, 4, 5)); // 2echo min(0, 'hello'); // 0ec ...
- How To Install Tinc and Set Up a Basic VPN on Ubuntu 14.04
Introduction In this tutorial, we will go over how to use Tinc, an open source Virtual Private Netwo ...
- Linux 性能检测 - CentOS 安装 paramon
简介 paramon是一款性能检测工具. 数据发送:cnt 数据接收:svr Continue...
- Ubuntu-1404 GDB 调试C++报错
问题 Ubuntu1404下,当用GDB调试C++程序时,报错ImportError: No module named 'libstdcxx' 解决办法 vim ~/.gdbinit #~/.gdbi ...
- LightOj 1163 - Bank Robbery(x-x/10 = n求所有的 x )
题目链接:http://lightoj.com/volume_showproblem.php?problem=1163 题意:有一个数A,然后去掉A的最后一位得到B,先告诉你A-B的值,求所有满足条件 ...
- js- 千分位分割
// 千分位 console.log(split3str("123456789")) function splitByReg3(str) { var re = /(\d{1,3}) ...
- Javascript位置 body之前、后执行顺序
简介:当页面加载的时候,嵌入html标记的js代码和位于<body></body>之间的js代码将被执行:当调用的时候,位于<head></head>之 ...