Codeforces round #247 for Div. 2
来源:互联网 发布:智能小车pid算法 编辑:程序博客网 时间:2024/05/16 15:47
英语不好,翻译了半天,看到别人3,4分钟就通过了,非常恼火,后来看懂发现就是映射数位,乘完就加就可以了。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;int a[5];string s;void init(){for(int i=1;i<=4;i++)cin>>a[i];cin>>s;long sum=0;for(int i=0;i<s.length();i++)sum+=a[s[i]-'0'];cout<<sum<<endl;}int main(){init();return 0;}
B. Shower Line
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.
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.
Print a single integer — the maximum possible total happiness of the students.
0 0 0 0 90 0 0 0 00 0 0 0 00 0 0 0 07 0 0 0 0
32
0 43 21 18 23 0 21 11 655 2 0 1 454 62 12 0 9987 64 81 33 0
620
In the first sample, the optimal arrangement of the line is 23154. In this case, the total happiness equals:
这个题目就是找个最大值吧类似,具体也说不清,看样例看懂的。别人都说是灌水算法,但是思考了一下一个全排列就可以了。实在想不明白怎么灌水做。。。
#include<iostream>#include<cstdio>#include<cstring>#include<Algorithm>#include<cmath>using namespace std;int n=0;int list[]={1,2,3,4,5};int ans[121][7];int sum=0;int m[6][6];void perm(int list[],int k,int m){if(k>m){for(int i=0;i<=m;i++)ans[n][i]=list[i];n++;}else {for(int i=k;i<=m;i++){swap(list[k],list[i]);perm(list,k+1,m);swap(list[k],list[i]);}}}void init(){for(int i=1;i<=5;i++)for(int j=1;j<=5;j++)cin>>m[i][j];perm(list,0,4);for(int i=0;i<n;i++){int t=0;t+=(m[ans[i][0]][ans[i][1]]+m[ans[i][1]][ans[i][0]]);t+=(m[ans[i][2]][ans[i][3]]+m[ans[i][3]][ans[i][2]]);t+=(m[ans[i][1]][ans[i][2]]+m[ans[i][2]][ans[i][1]]);t+=(m[ans[i][3]][ans[i][4]]+m[ans[i][4]][ans[i][3]]);t+=m[ans[i][2]][ans[i][3]]+m[ans[i][3]][ans[i][2]];t+=m[ans[i][3]][ans[i][4]]+m[ans[i][4]][ans[i][3]];if(t>sum)sum=t;/*9cout<<ans[n][0]<<" "<<ans[n][1]<<"--";cout<<ans[n][2]<<" "<<ans[n][3]<<"--";cout<<ans[n][4]<<endl;*/}cout<<sum<<endl;}int main(){init();return 0;}
- Codeforces round #247 for Div. 2
- Codeforces Round #247 (Div. 2)
- Codeforces Round #247 (Div. 2)
- Codeforces Round #247 (Div. 2)
- Codeforces Round#289(DIV.2) + qualifying round for WCC
- 【Codeforces Round #351 Div. 2】 673B Problems for Round
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)
- codeforces Educational Codeforces Round 33 (Rated for Div. 2)B
- Codeforces Round #236 (Div. 2)__Searching for Graph
- Codeforces Round #236 (Div. 2)C. Searching for Graph
- Codeforces Round #135 (Div. 2)VD. Choosing Capital for Treeland
- Codeforces Round #135 (Div. 2) D Choosing Capital for Treeland
- Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
- Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland
- Codeforces Round #135 (Div. 2)-D. Choosing Capital for Treeland
- Codeforces Round #440 (Div. 2) Search for Pretty Integers
- Codeforces Round #441 (Div. 2)A. Trip For Meal
- Codeforces Round #444 (Div. 2) B. Cubes for Masha
- 如何看懂ORACLE执行计划
- csdn好平台好网站
- Embarcadero RAD Studio XE6 安装没有 FireMonkey Mobile Application 解决方法
- input_dev结构体分析
- matlab 下 txt文件读取
- Codeforces round #247 for Div. 2
- Google Code Jam 2014 Qualification Round:D. Deceitful War
- 对于在textarea中用enter来提交表单之后又要清空其textarea中的值的时候
- Scala 脚本
- 认清自己的主干,不能大钱小钱都同等抓
- window下跑nginx,轻松实现负载均衡
- 树状数组&线段树&RMQ
- 关于Outlook Express里的.dbx的文件
- lr的并行化