折半搜索,先搜索一半的数字,记录第一个人的值,第二个人、第三个人和第一个人的差值,开个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的更多相关文章

  1. 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 ...

  2. 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/ ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #325 (Div. 2) Phillip and Trains dp

    原题连接:http://codeforces.com/contest/586/problem/D 题意: 就大家都玩过地铁奔跑这个游戏(我没玩过),然后给你个当前的地铁的状况,让你判断人是否能够出去. ...

  7. Codeforces Round #325 (Div. 2) Laurenty and Shop 模拟

    原题链接:http://codeforces.com/contest/586/problem/B 题意: 大概就是给你一个两行的路,让你寻找一个来回的最短路,并且不能走重复的路. 题解: 就枚举上下选 ...

  8. Codeforces Round #325 (Div. 2) Alena's Schedule 模拟

    原题链接:http://codeforces.com/contest/586/problem/A 题意: 大概就是给你个序列..瞎比让你统计统计什么长度 题解: 就瞎比搞搞就好 代码: #includ ...

  9. 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 ...

随机推荐

  1. 蓝牙Host Controller Interface笔记

    1.概述     HCI提供了一个统一的使用蓝牙控制器(BR/EDR Controller,BR/EDR/LE Controller,LE Controller,AMP Controller等)的方法 ...

  2. linux环境下的伪分布式环境搭建

    本文的配置环境是VMware10+centos2.5. 在学习大数据过程中,首先是要搭建环境,通过实验,在这里简短粘贴书写关于自己搭建大数据伪分布式环境的经验. 如果感觉有问题,欢迎咨询评论. 一:伪 ...

  3. ADO.NET连接到数据库(oracle)

    本文摘抄于http://www.cnblogs.com/luluping/archive/2009/10/13/1582737.html,如有侵权,请联系博主. OracleConnection 对象 ...

  4. 安装Sql server 2008时出现sql server 2005 express tools failed 怎么办?

    提示错误:Sql2005SsmsExpressFacet 检查是否安装了 SQL Server 2005 Express 工具. 失败,已安装 SQL Server 2005 Express 工具.若 ...

  5. VS2013搭建wxWidgets开发环境

    一.安装 前往官网下载最新wxWidgets 3.0.0. https://sourceforge.net/projects/wxwindows/files/3.0.0/wxMSW-3.0.0-Set ...

  6. LeetCode Closest Binary Search Tree Value II

    原题链接在这里:https://leetcode.com/problems/closest-binary-search-tree-value-ii/ 题目: Given a non-empty bin ...

  7. LeetCode Integer to English Words

    原题链接在这里:https://leetcode.com/problems/integer-to-english-words/ Convert a non-negative integer to it ...

  8. http和webservice接口区别

    httpservice通过post和get得到你想要的东西webservice就是使用soap协议得到你想要的东西,相比httpservice能处理些更加复杂的数据类型   http协议传输的都是字符 ...

  9. Android 使用shape来画线

    注意:Android3.0以上系统开始支持硬件加速特性hardwareAccelerated,默认是启用的.当你的某个activity用到了“虚线”效果的时候,必须要设置AndroidManifest ...

  10. 30天,APP创业从0到1【7.11郑州站】

    活动概况 时间:2015年07月11日13:30-16:30 地点:慧谷咖啡(郑州杨金路9号河南外包产业园天元W栋) 主办:APICloud.环信.河南中医药大学医药信息化实验室 网址:www.api ...