题目描述

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.

输入描述:

  1. 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.

输出描述:

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

输入

  1. 3
  2. 5
  3. 1 1 2 3 5
  4. 3
  5. 1 4 7
  6. 3
  7. 200 4 10000

输出

  1. 2
  2. 5
  3. 204

题解

找到最小值、次小值输出即可。

  1. #include<cstdio>
  2. using namespace std;
  3.  
  4. const double eps=1e-8;
  5. #define zero(x)(((x)>0?(x):(-x))<eps)
  6.  
  7. const int maxn = 1000000 + 10;
  8. long long a[maxn];
  9. int n;
  10. long long INF = 0x7FFFFFFF;
  11.  
  12. int main() {
  13. int T;
  14. scanf("%d", &T);
  15. while(T --) {
  16. scanf("%d", &n);
  17. for(int i = 1; i <= n; i ++) {
  18. scanf("%lld", &a[i]);
  19. }
  20. long long ans = 0;
  21. long long num;
  22. int pos1 = -1, pos2 = -1;
  23.  
  24. for(int i = 1; i <= n; i ++) {
  25. if(pos1 == -1) pos1 = i;
  26. if(a[i] < a[pos1]) pos1 = i;
  27. }
  28. for(int i = 1; i <= n; i ++) {
  29. if(pos1 == i) continue;
  30. if(pos2 == -1) pos2 = i;
  31. if(a[i] < a[pos2]) pos2 = i;
  32. }
  33. ans = a[pos1] + a[pos2];
  34. printf("%lld\n", ans);
  35. }
  36. return 0;
  37. }

  

湖南大学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. vmware中无法ping通主机的问题

    虚拟机使用NAT方式运行一段时间后,发现无法ping通主机(物理机),显示错误如下 ipconfig如下 查看虚拟机中的网络连接,显示"未识别网络" 分析: 查看了网络上的一些资料 ...

  2. NOIP模拟赛9

    T1U3348 A2-回文数 https://www.luogu.org/problem/show?pid=U3348 考场上钻了牛角尖了,然后0分 #include<cstdio> #i ...

  3. dp ZOJ 3956

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3956 Course Selection System Time Limit ...

  4. Atcoder #017 agc017 D.Game on Tree 树上NIM 博弈

    LINK 题意:树上NIM的模板题,给出一颗树,现有操作删去端点不为根节点的边,其另一端节点都将被移除,不能取者为败 思路:一看就是个NIM博弈题,只是搬到树上进行,树上DFS进行异或 记得#014D ...

  5. WIN7 系统 右键计算机 点击管理 出现对话框:找不到文件。

    解决方法: WIN+R组合键运行 “regedit” HKEY_LOCAL_MACHINE----SOFTWARE----Classes----CLSID----{20D04FE0-3AEA-1069 ...

  6. JavaScript:详解 Base64 编码和解码

    Base64是最常用的编码之一,比如开发中用于传递参数.现代浏览器中的<img />标签直接通过Base64字符串来渲染图片以及用于邮件中等等.Base64编码在RFC2045中定义,它被 ...

  7. 12款jQuery幻灯片插件和幻灯片特效教程

    jQuery 使用简单灵活,同时还有许多成熟的插件可供选择,它可以帮助你在项目中加入一些非常好的效果.滑块和幻灯片效果是常用的内容展示方式之一,这是一种在有限的网页空间内展示系列项目时非常好的方法.今 ...

  8. DOM使用

    DOM树模型 document |-html |-head |-.... |-body |-..... 要解析页面的前提是要拿到一个对象,然后利用树之间前后的关系进行对象的遍历和操作. 在DHTML的 ...

  9. R3—日期处理

    一. 问题引入 下面是一个房地产价格数据,现在想要提取2008年6月份的数据进行分析,在R中该如何操作呢? city price bedrooms squarefeet lotsize latitud ...

  10. phpcms直接取子栏目的内容、调用点击量的方法

    子栏目里面的内容可以直接取,而不需要通过循环. {$CATEGORYS[$catid][catname]}//取子栏目的栏目名称 {$CATEGORYS[$catid][image]}//取子栏目的栏 ...