浙江科技学院第十三届程序设计竞赛 1008:A Heavy Rainy Day【贪心】
2016-03-26 20:42
423 查看
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 were playing League of Legends in the lab, of course not include me, while it was raining cats and dogs. Everyonewanted 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
AC-code:
#include<cstdio> <pre name="code" class="cpp">#include<algorithm> #include<cstring> using namespace std; int main() { int T,n,i,ans,s[1005]; scanf("%d",&T); while(T--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&s[i]); sort(s,s+n); ans=0; while(n>=4) { if(2*s[0]+s[n-1]+s[n-2]>s[0]+s[n-1]+2*s[1]) ans+=s[0]+s[n-1]+2*s[1]; else ans+=2*s[0]+s[n-1]+s[n-2]; n-=2; } if(n==3) ans+=s[n-1]+s[n-2]+s[n-3]; else if(n==2) ans+=s[1]; else if(n==1) ans+=s[0]; printf("%d\n",ans); } return 0; }
相关文章推荐
- hdoj--A Heavy Rainy Day(贪心好题)
- LeetCode172. Factorial Trailing Zeroes
- 增加samba用户提示Failed to add entry for user
- Educational Codeforces Round 5 E. Sum of Remainders
- AIDL调用指南
- 加入百度地图遇到 framework not found BaiduMapAPI***
- 在main方法中调用service
- HDU1021-Fibonacci Again,,找规律就好了~~~
- golang sync WaitGroup
- Hive连接Mysql---FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask.
- Eval()和DataBinder Eval(Container DataItem,)的区别及用法
- Airplane mode的三种切换方式
- PAT (Advanced Level) Practise 1106 Lowest Price in Supply Chain (25)
- 你应该知道的最好Webmail邮件客户端,
- 8款世界级Webmail工具推荐
- jps 报process information unavailable解决办法
- coderforce Educational Codeforces Round 10 C. Foe Pairs(贪心)
- FATAL: Peer authentication failed for user "geo_rails_test_creator"
- Codeforences Educational Round10 C. Foe Pairs
- [LeetCode] Paint House II 粉刷房子之二