湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks
2017-12-24 19:56
295 查看
题目描述
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【排序】
- 湖南大学ACM程序设计新生杯大赛(同步赛) D -Number 【打表+暴力】
- 湖南大学ACM程序设计新生杯大赛(同步赛)E-Permutation【打表+规律】
- 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
- 湖南大学ACM程序设计新生杯大赛(同步赛) I-Piglet treasure hunt Series 1【BFS】
- 湖南大学ACM程序设计新生杯大赛(同步赛) I-Piglet treasure hunt Series 1【BFS】
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
- 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
- 湖南大学ACM程序设计新生杯大赛(同步赛)A-Array 【证明+暴力】
- 湖南大学ACM程序设计新生杯大赛(同步赛)C-Do you like Banana ? 【几何】
- CRT detected that the application wrote to memory after end of heap buffer
- 文件系统不同步问题resource is out of sync with the file system的解决办法
- CRT detected that the application wrote to memory after end of heap buffer
- C语言错误: CRT detected that the application wrote to memory after end of heap buffer
- 湖南大学ACM程序设计新生杯大赛 - A Array
- 【debug】CRT detected that the application wrote to memory after end of heap buffer
- The Dangers of the Large Object Heap(转载,LOH内存碎片情景重现)
- 湖南大学ACM程序设计新生杯大赛 - B Build