您的位置:首页 > 其它

湖南大学ACM程序设计新生杯大赛(同步赛)G-The heap of socks【排序】

2017-12-24 18:42 417 查看
时间限制:C/C++ 1秒,其他语言2秒

空间限制:C/C++ 32768K,其他语言65536K

64bit IO Format: %lld

题目描述

BSD is a lazy boy. He doesn’t want to wash his socks, but he will have a data structure called ‘socks heap’.By maintaining this structure, he can quickly pick out two of the most smelless socks from millions of socks everyday. As one of his good friends, you know the data structure of BSD, and want to predict ‘the air pollution level’ of a certain day. Of course, it’s BSD’s socks that pollute the air.

We will enter numbers that indices for ‘socks smell level’ and expect you to output the total amount of pollution that he will wear on the day of BSD design.

输入描述:

First line contain an integer T 1<T<=10 ,means the sum of test cases.

for every test cases,we will firstly give N(1<N<1000000) in a single line,means the count of socks.Next line Contains N numbers (you can use int to save all of them) ,means ‘smell level’ for every socks.

输出描述:

please putout answer in a single line for every test cases.

示例1

输入

3

5

1 1 2 3 5

3

1 4 7

3

200 4 10000

输出

2

5

204

题意:找出两个臭味最小的袜子 。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long int
using namespace std;
const int maxn = 1e6 + 10;
int a[maxn];
int main()
{
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n);
ll ans = 1ll*(a[2] + a[1]);
printf("%lld\n", ans);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐