题目描述

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. [DeeplearningAI笔记]卷积神经网络3.10候选区域region proposals与R-CNN

    4.3目标检测 觉得有用的话,欢迎一起讨论相互学习~Follow Me 3.10 region proposals候选区域与R-CNN 基于滑动窗口的目标检测算法将原始图片分割成小的样本图片,并传入分 ...

  2. 谷歌地图 API 开发之添加标记(解析以及补充)

    今天又看了下官网,发现官网上有地图标记的详细说明.当时居然眼瞎看不见,还琢磨了好久...#$%^&,一定是项目太急,没看到(^o^)/~地址:https://developers.google ...

  3. 复制自身程序到windows目录和system32目录下

    功能:复制自身到windows目录和system32目录下. 参考代码: #include <stdio.h> #include <windows.h> void CopySe ...

  4. [Luogu 1351] NOIP2014 联合权值

    [Luogu 1351] NOIP2014 联合权值 存图,对于每一个点 \(u\),遍历它的所有邻接点.以 \(u\) 为中转点的点对中,\((x,y)\) 的联合权值 \(w_x \cdot w_ ...

  5. hbase性能调优案例

    hbase性能调优案例 1.人员-角色   人员有多个角色  角色优先级   角色有多个人员   人员 删除添加角色   角色 可以添加删除人员   人员 角色 删除添加   设计思路 person表 ...

  6. (4.1)LingPipe在Eclipse中的运行

    酒店评论情感分析系统(四)——LingPipe在Eclipse中的运行 本来打算在做这个项目的时候,使用基于语义的文本倾向性分析方法,即先通过对评论文本进行中文分析,去停用词,然后在倾向性语义模式库的 ...

  7. IIS 网站日志分析

    最近由于ADSL代理总出问题,导致爬虫服务器总被目标网站封,由于请求内容总是空,前端APP获取不到想要的内容就一直刷新,导致爬虫服务器请求更加繁忙. 爬虫服务器每执行完一个流程,都会给统计服务器Pos ...

  8. ActiveMQ笔记之安装(Linux)

    1. 基本概念 MQ(MessageQueue),消息队列,是一个消息接收和转发的容器. Apache ActiveMQ是一个JMS Provider实现. 2. 安装 从官网下载安装包: wget ...

  9. python使用unittest模块selenium访问斗鱼获取直播信息

    import unittest from selenium import webdriver from bs4 import BeautifulSoup as bs class douyu(unitt ...

  10. Spring 控制台运行及RestTemplate实现Eurka负载均衡

    spring使用控制台运行方式 spring.main.web-application-type=none新老版本的配置有点差异 Maven的modules只是实现了一个顺序编译,一次多个项目一起生成 ...