codeforces B. Shower Line 解题报告
题目链接:http://codeforces.com/contest/431/problem/B
题目意思:给出5 * 5 的矩阵。从这个矩阵中选出合理的安排次序,使得happiness之和最大。当第i个人和第j个人talk 的时候,第i个人获得的happiness是g[i][j],第j 个人获得的happiness是g[j][i]。
好简单的一道题目,不知道昨晚徘徊好久都不敢打,五个for循环即可!数据量这么小......今天一次就过了...
谨以此来纪念自己的怯懦....
方法一:直接暴力枚举
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std; #define LL long long
int g[][];
LL ans; int main()
{
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
scanf("%d", &g[i][j]);
}
ans = ;
for (int i = ; i <= ; i++)
{
for (int j = ; j <= ; j++)
{
if (i != j)
{
for (int k = ; k <= ; k++)
{
if (k != j && k != i)
{
for (int l = ; l <= ; l++)
{
if (l != k && l != i && l != j)
{
for (int p = ; p <= ; p++)
{
if (p != l && p != i && p != j && p != k)
{
// printf("i = %d, j = %d, k = %d, l = %d, p = %d\n", i, j, k, l, p);
LL sum = g[i][j] + g[j][i] + g[j][k] + g[k][j] + * (g[l][p] + g[p][l] + g[k][l] + g[l][k]);
ans = max(ans, sum);
}
}
}
}
}
}
}
}
}
printf("%lld\n", ans);
return ;
}
方法二:利用next_permutation (学人家代码写的)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std; #define LL long long
const int maxn = ;
int grid[maxn+][maxn+];
int t[maxn];
LL ans, tmp; int main()
{
for (int i = ; i < maxn; i++)
{
for (int j = ; j < maxn; j++)
scanf("%d", &grid[i][j]);
}
for (int i = ; i < maxn; i++)
t[i] = i;
ans = ;
do
{
//0123: 01 talk 23 talk
tmp = grid[t[]][t[]] + grid[t[]][t[]];
tmp += grid[t[]][t[]] + grid[t[]][t[]];
//1234: 12 talk 34 talk
tmp += grid[t[]][t[]] + grid[t[]][t[]];
tmp += grid[t[]][t[]] + grid[t[]][t[]];
//23: 23 talk
tmp += grid[t[]][t[]] + grid[t[]][t[]];
//34: 34 talk
tmp += grid[t[]][t[]] + grid[t[]][t[]]; ans = max(ans, tmp);
}while (next_permutation(t, t+maxn));
printf("%lld\n", ans);
return ;
}
codeforces B. Shower Line 解题报告的更多相关文章
- codeforces A. Cinema Line 解题报告
题目链接:http://codeforces.com/problemset/problem/349/A 题目意思:题目不难理解,从一开始什么钱都没有的情况下,要向每一个人售票,每张票价格是25卢布,这 ...
- Codeforces Round 665 赛后解题报告(暂A-D)
Codeforces Round 665 赛后解题报告 A. Distance and Axis 我们设 \(B\) 点 坐标为 \(x(x\leq n)\).由题意我们知道 \[\mid(n-x)- ...
- Codeforces Round 662 赛后解题报告(A-E2)
Codeforces Round 662 赛后解题报告 梦幻开局到1400+的悲惨故事 A. Rainbow Dash, Fluttershy and Chess Coloring 这个题很简单,我们 ...
- Codeforces Round #277.5 解题报告
又熬夜刷了cf,今天比正常多一题.比赛还没完但我知道F过不了了,一个半小时贡献给F还是没过--应该也没人Hack.写写解题报告吧= =. 解题报告例如以下: A题:选择排序直接搞,由于不要求最优交换次 ...
- codeforces A. Dima and Continuous Line 解题报告
题目链接:http://codeforces.com/problemset/problem/358/A 题目意思:在横坐标上给出n个不同的点,需要把前一个点跟后一个点(这两个点的顺序是紧挨着的)用一个 ...
- codeforces B. Simple Molecules 解题报告
题目链接:http://codeforces.com/problemset/problem/344/B 题目意思:这句话是解题的关键: The number of bonds of an atom i ...
- 【LeetCode】149. Max Points on a Line 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 字典+最大公约数 日期 题目地址:https://l ...
- codeforces 591A. Wizards' Duel 解题报告
题目链接:http://codeforces.com/problemset/problem/591/A 题目意思:其实看下面这幅图就知道题意了,就是Harry 和 He-Who-Must-Not-Be ...
- codeforces 582A. GCD Table 解题报告
题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...
随机推荐
- RRAS
远程访问控制是Windows NT.Win200x Server提供的一种远程服务,它允许用户从远端通过拨号连接连接到一个本地的计算机网络,一旦建立了连接,就相当于处在了本地的LAN中,从而可以使用各 ...
- ThinkPHP5.1入门
ThinkPHP5.1入门 ===================================Composer的官方网站:https://www.phpcomposer.com/========= ...
- mac 获得进程信息的方法
NSProcessInfo可以获得当前进程的信息.获得所有活动进程信息可以尝试使用下面的方法. 进程的信息可以通过ps命令得到也可以通过sysctl方法得到. 但是我总是不能获取进程的流量信息,关于这 ...
- POJ 1509 Glass Beads【字符串最小表示法】
题目链接: http://poj.org/problem?id=1509 题意: 求循环字符串的最小表示. 分析: 浅析"最小表示法"思想在字符串循环同构问题中的应用 判断两字符串 ...
- Struts2防止重复提交
一般使用<interceptor-ref name="token"></interceptor-ref>或者<interceptor-ref name ...
- 2017-10-29-morning-清北模拟赛
T1 遭遇 #include <algorithm> #include <cstdio> #include <cmath> inline void read(int ...
- 设计模式之建造者(Builder)模式
设计模式之建造者(Builder)模式 存在一些情况,比如,一些对象会有一些重要的属性,在这些属性没有恰当的值之前,对象不能作为一个完整的产品使用(如一个电子邮件最起码得有收件人地址):还有一些些情况 ...
- 快速上传到rackspace cdn工具turbolift swift 安装
快速上传到rackspace cdn 工具安装,2步即可完成: 1.安装git CentOS的yum源中没有git,只能自己编译安装,现在记录下编译安装的内容,留给自己备忘. 确保已安装了依赖的包 y ...
- windows redis 服务安装坑
环境 winserver 2012 最新版的redis:3.0.503 redis-server.exe --service-install redis.windows.conf --m ...
- Xcode 技巧充电篇
作为project师,我们最重要的事情就是熟悉我们每天使用的日常工具,但不能仅限于此.仅仅要有可能,我们应该试着掌握和定制能使我们更快.更轻松地实现终于目标的工具.以下是一些小提示和技巧,都是我在 X ...