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

题目描述

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;
}

  

时间: 2024-11-07 15:06:08

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

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

题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e18) guys standing in a row, because the boys had some strange character,The first time to Liao them will not be successful, but the second time will be su

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

题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, only some roads can be built.That is to say,if the limit is 100$, only roads whose cost are no more than 100$ can be built. Now give you n cities, m r

湖南大学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 found itself in a strange land of treasure. As for how to come in, or how to go out, no ways to know. Sad. The good news is, it was lucky that it got the

湖南大学第十四届ACM程序设计新生杯 Dandan&#39;s lunch

Dandan's lunch Description: As everyone knows, there are now n people participating in the competition. It was finally lunch time after 3 hours of the competition. Everyone brought a triangular bread. When they were going to eat bread, some people fo

湖南大学第十四届ACM程序设计新生杯 E.Easy Problem

E.Easy Problem Description: Zghh likes number, but he doesn't like writing problem description. So he will just give you a problem instead of telling a long story for it. Now given a positive integer x and k digits a1,a2,...,ak, can you find a positi

华中农业大学第四届程序设计大赛网络同步赛 G.Array C 线段树或者优先队列

Problem G: Array C Time Limit: 1 Sec  Memory Limit: 128 MB Description Giving two integers  and  and two arrays  and  both with length , you should construct an array  also with length  which satisfied: 1.0≤Ci≤Ai(1≤i≤n) 2. and make the value S be min

H. GSS and Simple Math Problem--“今日头条杯”首届湖北省大学程序设计竞赛(网络同步赛)

题目描述:链接点此 这套题的github地址(里面包含了数据,题解,现场排名):点此 题目描述 Given n positive integers , your task is to calculate the product of these integers, The answer is less than 输入描述: The first line of input is an integer n, the i-th of the following n lines contains the

哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练. 题解: E666 这个题是让求有多少个子串只含有6.寻找连续的6,然后用n*(n+1)/2求出这一段的子串个数,然后把每一段连续的加起来. 做的时候wa了很多次,原来是在n*(n+1)的地方已经超过int型了,所以需要设置类型为long long. #include <cstdio> #inc

2016广东工业大学新生杯决赛网络同步赛暨全国新生邀请赛 题解&amp;源码

Problem A: pigofzhou的巧克力棒 Description 众所周知,pigofzhou有许多妹子.有一天,pigofzhou得到了一根巧克力棒,他想把这根巧克力棒分给他的妹子们.具体地,这根巧克力棒长为 n,他想将这根巧克力棒折成 n 段长为 1 的巧克力棒,然后分给妹子们. 但是他妹子之一中的 15zhazhahe 有强迫症.若它每次将一根长为 k 的巧克力棒折成两段长为 a 和 b 的巧克力棒,此时若 a=b,则15zhazhahe会得到一点高兴值. pigofzhou想知