浙江科技學院第十三屆程式設計競賽1008

來源:互聯網
上載者:User
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. 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
141 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>







聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.