浙江科技学院第十三届程序设计竞赛1008
2016-03-26 21:46
232 查看
A Heavy Rainy Day
Time Limit : 3000/1000ms (Java/Other) Memory Limit : 65535/32768K (Java/Other)Total Submission(s) : 475 Accepted Submission(s) : 124
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
As you know, Hangzhou always rains heavily, especially in Xiaoheshan area, which does annoy ACMers for a longer time. One day, N hardworking ACMers wereplaying League of Legends in the lab, of course not include me, while it was raining cats and dogs. Everyone wanted to come back to the department where they were living together, but no one wanted to be soaked without umbrella. Unfortunately, they only had
one umbrella, which is too small to take more than two individuals. The time that everyone needs to spent to go to the department is known. If two guys came back together, it will take the longer time of this two guys. The question is the earliest time they
come back to the department.
Input
The first line contains an integer T(1<=T<=20),which is the number of test cases.For each testcase:
The first line contains one integer N ,1<=N<=1000, present N ACMers want to come back,
The second line contains N integers Si, present the time the ith ACMers need.
Output
The shortest time they need to come to the department.Sample Input
1 4 1 2 5 10
Sample Output
17
这道题需要四个一组考虑最优解
<span style="font-family:KaiTi_GB2312;font-size:24px;">#include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<cmath> using namespace std; int a[1010]; int main() { int n; scanf("%d",&n); while(n--) { int m; scanf("%d",&m); for(int i=0;i<m;i++) { scanf("%d",&a[i]); } sort(a,a+m); int sum=0,q,p; while(m>3) { q=a[0]+a[1]*3+a[m-1]; p=a[0]*2+a[1]+a[m-1]+a[m-2]; if(q>p) sum+=p-a[1]; else sum+=q-a[1]; m-=2; } if(m==1) sum+=a[0]; if(m==2) sum+=a[1]; if(m==3) sum+=a[0]+a[1]+a[2]; printf("%d\n",sum); } return 0; }</span>
相关文章推荐
- 在OSX上开发UNITY本地插件的经验分享
- IOS本地通知实现
- 与运算与异或运算的应用
- 如何建立自己的知识体系
- 大整数相乘问题
- Android开源框架Universal-Image-Loader详解
- 第4次作业
- java 多线程
- 《JAVA笔记 day08 静态_单例》
- JS 事件处理初探秘
- xcache
- Play Framework 2.50体验
- 常量、变量、运算符、表达式和赋值语句的使用
- windows配置Java环境
- 浅谈Android MVP设计模式(简单结合RxJava+Retrofit)
- 写一个程序,用于分析一个字符串中各个单词出现的频率,并将单词和它出现的频率输出显示。(单词之间用空格隔开,如“Hello World My First Unit Test”)
- vc 导出函数/调用
- java foreach 以及collections 排序
- 正则表达式
- 课堂总结