折半搜索,先搜索一半的数字,记录第一个人的值,第二个人、第三个人和第一个人的差值,开个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. Windows下查看机器监听端口

    1.查看所有端口占用情况 在开始-运行-cmd,输入:netstat –ano可以查看所有进程 2.查看指定端口的占用情况      netstat -an |findstr :21 

  2. 删除本地git版本库中受版本控制的文件

     git乱码解决方案汇总 乱码原因 搜索一番,发现git文件名.log乱码,是普遍问题,这其中有编码的原因,也有跨平台的原因.主要原因是Windows 系统中的Git对中文文件名采用不同的编码保存所致 ...

  3. Mschat控件示例升级错误处理方法

    将具有 3.5 版图表控件的 ASP.NET 3.5 网站升级到 ASP.NET 4 需要更改 web.config 和注册指令 将具有 3.5 版图表控件的 ASP.NET 3.5 网站升级到 AS ...

  4. php--tp3.2引入sphinx搜索

    1.首先我们把coreseek下载好,命名为coreseek,我们找到coreseek/etc中的csft_mysql.conf修改这个配置文件 #源定义 source lemai { type    ...

  5. Delphi FindowWindow,FindowWindowEx

    unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...

  6. Solr4+IKAnalyzer的安装配置

    一.下载Solr4.10.2 我们以Windows版本为例,solr-4.10.2.zip是目前最新版本,下载地址: http://www.apache.org/dyn/closer.cgi/luce ...

  7. BI 商业智能理解结构图

    本文章是在本人实习阶段对BI(商业智能 Business Intelligence)的理解:(如有不足之处请多指教,谢谢) BI 系统负责从多个数据源中搜集数据,并将这些数据进行必要的转换后存储到 ...

  8. Wall---hdu1348(求凸包周长 模板)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1348 求凸包周长+2*PI*L: #include <stdio.h> #include ...

  9. An unknown Subversion error occurred. (code = 155037)

    这是因为在svn更新时意外中断引起的. 我的解决办法:如果本地没有更改,只是单纯获取svn的项目,则另起一个文件夹,重新checkout: 如果是本地有更改,则复制到新的文件夹,重新update.

  10. 个人常用iOS第三方库以及XCode插件介绍

    第三方库 CocoaPod CocoaPod并不是iOS上的第三方库 而是大名鼎鼎的第三方库的管理工具 在CocoaPod没有出现之前 第三方库的管理是非常痛苦的 尤其是一些大型的库(比如nimbus ...