Codeforces Round #247 (Div. 2) B. Shower Line(简单模拟)
2017-01-14 00:47
781 查看
B. Shower Line
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters
the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.
Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th
one.
Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't
talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5
enters the shower, and then 4 enters the shower.
We know that if students i and j talk, then the i-th student's happiness increases by gij and
the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of
all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.
Input
The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≤ gij ≤ 105).
It is guaranteed that gii = 0 for all i.
Assume that the students are numbered from 1 to 5.
Output
Print a single integer — the maximum possible total happiness of the students.
Sample test(s)
Input
0 0 0 0 90 0 0 0 00 0 0 0 00 0 0 0 07 0 0 0 0
Output
Input
0 43 21 18 23 0 21 11 6554 62 12 0 995 2 0 1 487 64 81 33 0
Output
Note
In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:
(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32
思路:
5个可爱的男孩子排队洗澡,顺序任意排列,则有5!方案,枚举即可;
且 一开始 与 每进去一个男孩子 之后,偶数位的人可以与之前的人说话,彼此都可以获取神秘的快乐能量;
求能量的最大值,模拟即可。
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Many students live in a dormitory. A dormitory is a whole new world of funny amusements and possibilities but it does have its drawbacks.
There is only one shower and there are multiple students who wish to have a shower in the morning. That's why every morning there is a line of five people in front of the dormitory shower door. As soon as the shower opens, the first person from the line enters
the shower. After a while the first person leaves the shower and the next person enters the shower. The process continues until everybody in the line has a shower.
Having a shower takes some time, so the students in the line talk as they wait. At each moment of time the students talk in pairs: the (2i - 1)-th man in the line (for the current moment) talks with the (2i)-th
one.
Let's look at this process in more detail. Let's number the people from 1 to 5. Let's assume that the line initially looks as 23154 (person number 2 stands at the beginning of the line). Then, before the shower opens, 2 talks with 3, 1 talks with 5, 4 doesn't
talk with anyone. Then 2 enters the shower. While 2 has a shower, 3 and 1 talk, 5 and 4 talk too. Then, 3 enters the shower. While 3 has a shower, 1 and 5 talk, 4 doesn't talk to anyone. Then 1 enters the shower and while he is there, 5 and 4 talk. Then 5
enters the shower, and then 4 enters the shower.
We know that if students i and j talk, then the i-th student's happiness increases by gij and
the j-th student's happiness increases by gji. Your task is to find such initial order of students in the line that the total happiness of
all students will be maximum in the end. Please note that some pair of students may have a talk several times. In the example above students 1 and 5 talk while they wait for the shower to open and while 3 has a shower.
Input
The input consists of five lines, each line contains five space-separated integers: the j-th number in the i-th line shows gij (0 ≤ gij ≤ 105).
It is guaranteed that gii = 0 for all i.
Assume that the students are numbered from 1 to 5.
Output
Print a single integer — the maximum possible total happiness of the students.
Sample test(s)
Input
0 0 0 0 90 0 0 0 00 0 0 0 00 0 0 0 07 0 0 0 0
Output
32
Input
0 43 21 18 23 0 21 11 6554 62 12 0 995 2 0 1 487 64 81 33 0
Output
620
Note
In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:
(g23 + g32 + g15 + g51) + (g13 + g31 + g54 + g45) + (g15 + g51) + (g54 + g45) = 32
思路:
5个可爱的男孩子排队洗澡,顺序任意排列,则有5!方案,枚举即可;
且 一开始 与 每进去一个男孩子 之后,偶数位的人可以与之前的人说话,彼此都可以获取神秘的快乐能量;
求能量的最大值,模拟即可。
#include <queue> #include <functional> #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <stack> #include <vector> #include <set> #include <map> #include <string> #include <cmath> #include <cstdlib> #include <ctime> #include <assert.h> #define REP(i,k,n) for(int i=k;i<n;i++) #define REPP(i,k,n) for(int i=k;i<=n;i++) #define scan(d) scanf("%d",&d) #define scann(n,m) scanf("%d%d",&n,&m) #define mst(a,k) memset(a,k,sizeof(a)); #define LL long long #define eps 1e-8 #define INF 0x6f6f6f6f #define mod 1000000007 #define PI acos(-1.) using namespace std; #define N 15 #define M 1005 int num ; int f(int a,int b,int c,int d,int e) //暴力模拟 { return num[a][b]+num[b][a]+num[c][d]+num[d][c]+num[b][c]+num[c][b]+num[d][e]+num[e][d]+num[c][d]+num[d][c]+num[d][e]+num[e][d]; } int main() { for(int i=0;i<5;i++){ for(int j=0;j<5;j++){ scanf("%d",&num[i][j]); } } int ans = 0; for(int i=0;i<5;i++){ // 5层for 暴力枚举 for(int j=0;j<5;j++){ if(i==j) continue; for(int k=0;k<5;k++){ if(i==k||j==k) continue; for(int l=0;l<5;l++){ if(i==l||j==l||k==l) continue; for(int t=0;t<5;t++){ if(i==t||j==t||k==t||l==t) continue; ans = max(ans,f(i,j,k,l,t)); } c30e } } } } cout<<ans<<endl; return 0; }
相关文章推荐
- Codeforces Round #175 (Div. 2) B. Find Marble(简单模拟)
- Codeforces Round #247 (Div. 2)a.Black Square,b.Shower Line,c.k-Tree前三题
- Codeforces Round #366 (Div. 2) A. Hulk (简单模拟)
- Codeforces Round #402 (Div. 2) C. Dishonest Sellers 简单模拟
- Codeforces Round #403 (Div. 2) A. Andryusha and Socks(简单模拟)
- js简单模拟div注册登录功能
- Codeforces Round #457 (Div. 2) A. Jamie and Alarm Snooze简单模拟
- Codeforces Round #199 (Div. 2) -- B. Xenia and Spies (简单模拟)
- Codeforces Round #360 (Div. 2) 前三题题解【简单模拟+思维+二分图判定二分染色】
- 【Codeforces Round 354 (Div 2)B】【简单模拟】Pyramid of Glasses
- HDU 3623 Best Cow Line, Gold(模拟,注意思路,简单)
- cf#323-div2-A. Asphalting Roads-简单模拟
- Codeforces Round #109 (Div. 2) A (简单模拟)
- CF #364 (Div. 2)( A. Cards 简单模拟)
- Codeforces Beta Round #92 (Div. 2) / 124A The number of positions 【简单模拟】【水题】
- Codeforces Round #239 (Div. 2) A. Line to Cashier(简单题)
- Codeforces Round #107 (Div. 2) B (简单模拟)
- 【Codeforces Round 333 (Div 2)A 】【水题 简单进制模拟】Two Bases 不同进制数比大小
- Codeforces Round #377 (Div. 2) D. Exams 贪心 + 简单模拟
- B. Tell Your World Codeforces Round #431 (Div. 2)(简单模拟)