题目描述

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<cstdio>
using namespace std; const double eps=1e-8;
#define zero(x)(((x)>0?(x):(-x))<eps) const int maxn = 1000000 + 10;
long long a[maxn];
int n;
long long INF = 0x7FFFFFFF; int main() {
int T;
scanf("%d", &T);
while(T --) {
scanf("%d", &n);
for(int i = 1; i <= n; i ++) {
scanf("%lld", &a[i]);
}
long long ans = 0;
long long num;
int pos1 = -1, pos2 = -1; for(int i = 1; i <= n; i ++) {
if(pos1 == -1) pos1 = i;
if(a[i] < a[pos1]) pos1 = i;
}
for(int i = 1; i <= n; i ++) {
if(pos1 == i) continue;
if(pos2 == -1) pos2 = i;
if(a[i] < a[pos2]) pos2 = i;
}
ans = a[pos1] + a[pos2];
printf("%lld\n", ans);
}
return 0;
}

  

湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks的更多相关文章

  1. 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

    题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...

  2. 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array

    题目描述 Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...

  3. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  4. 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

    题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, ...

  5. 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1

    题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...

  6. 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation

    题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...

  7. 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number

    题目描述 We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), ...

  8. 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons

    题目描述 Yuanyuan Long is a dragon like this picture?                                     I don’t know, ...

  9. 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?

    题目描述 Two endpoints of two line segments on a plane are given to determine whether the two segments a ...

随机推荐

  1. 解决问题Can’t connect to local MySQL server through socket

    不幸遇到MySQL出现ERROR 2002 (HY000): Can’t connect to local mysql server through socket ‘/tmp/mysql.sock’错 ...

  2. Spring整合JMS(四)——事务管理(转)

    *注:别人那复制来的 Spring提供了一个JmsTransactionManager用于对JMS ConnectionFactory做事务管理.这将允许JMS应用利用Spring的事务管理特性.Jm ...

  3. Atcoder arc077 D - 11 组合

    Link 题意:给出n个数,其中有一个数会出现两次,其余数只出现一次,问不同长度且不同的子串的数量.取模1e9+7 思路:组合求出所有情况,减去重复情况,注意用逆元即可 /** @Date : 201 ...

  4. python中拷贝对象的区别

    一.赋值.引用 在python中赋值语句总是建立对象的引用值,而不是复制对象.因此,python变量更像是指针,而不是数据存储区域 这点和大多数语音类似吧,比如C++.Java等 1.先看个例子: v ...

  5. 重构改善既有代码设计--重构手法19:Replace Data Value with Object (以对象取代数据值)

    你有一笔数据项(data item),需要额外的数据和行为. 将这笔数据项变成一个对象. class Order... private string customer; ==> class Or ...

  6. Spring websocket浏览器连接时出现404错误

    1.场景 在用websocket做一个简单的数据导入页面同步显示后台进度功能的时候,浏览器出现连接不上的错误: WebSocket connection to 'ws://localhost:8080 ...

  7. 如何实用便捷的在本地真机调试WEB端HTML5网页

    先简单介绍两款常用但需要一定条件或限制的工具 1.如果你能FQ chrome在32版本后就自带了移动端调度工具,可以在Android直接联调,但唯一遗憾的是,在我大天朝要FQ后才能行的通,我自己试了后 ...

  8. 011 CountDownLatch,CyclicBarrier和Semaphore

    CountDownLatch(闭锁,有译倒计数,锁寄存): public class CountDownLatchTest { /*** 比如有一个任务A,它要等待其他4个任务执行完毕之后才能执行,此 ...

  9. ButterKnifeZelezny简单使用教程

    https://github.com/avast/android-butterknife-zelezny     一,配置butterknife Configure your project-leve ...

  10. 中国区的Azure添加到 VSTS 的 Service Endpoint

    把中国区的Azure添加到 VSTS (Visual Studio Team System) 的 Service Endpoint. 这个是使用 VSTS 自动部署到中国区Azure的前置条件. Se ...