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 ...
随机推荐
- Cookie操作
1.写cookie方法 #region 登录时写入cookie public static void LoginCookieSave(string uid, string loginname, str ...
- $watch、$digest、$apply
$watch.$digest.$apply $watch 代表的就是对数据源的监听,当数据源发生变化,就会触发第二个参数的回调函数 $digest 代表触发一个数据源变化的事件 $apply 代表对于 ...
- Scala Tail Recursion (尾递归)
Scala对尾递归进行了优化,甚至提供了专门的标注告诉编译器需要进行尾递归优化.不过这种优化仅限于严格的尾递归,间接递归等情况,不会被优化. 尾递归的概念 递归,大家都不陌生,一个函数直接或间接的调用 ...
- int a=5,则 ++(a++)的值是?
编译出错:++(a++)先计算的是括号里的(a++),返回的结果是一个表达式,其值是5,不能对表达式进行赋值
- Cocos2d-JS引入其他场景小实例
创建新项目,目标是把LogoNode.js场景引入app.js 新建LogoNode.js var LogoLayer = cc.Layer.extend({ ctor:function () { t ...
- 用javascript实现用户登录验证
<script language=javascript> function checkSubmit() { if ((document.form1.name.value)=="& ...
- 其他常用HTML 片段
1.input placeholder 文字居中 字体大小+上下padding值等于设计稿宽度 设计稿中总高度为86px padding:27px 0;font-size:30px; 2.英文 ...
- 将option添加到select框
var select=document.createElement("select"); select.setAttribute("class","f ...
- ul和ol的一些知识
ul和ol的一些知识 div#div0 ul{ border:1px solid #ccc; list-style:none; } div#div0 ul li{ border:1px solid g ...
- Android实现app长时间未操作时自动退出app
这里要考虑3个问题,第一个是锁屏问题,第二个是app被切换至后台的问题,第三个是屏幕锁定和解除时app在后台时的问题 一,监听屏幕解锁,锁定 ? 1 2 3 4 5 6 7 8 9 10 11 12 ...