zoukankan      html  css  js  c++  java
  • 湖南大学ACM程序设计新生杯大赛(同步赛)G

    题目描述

    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
    ", ans);
      }
      return 0;
    }
    

      

  • 相关阅读:
    【笔记】【dp模型】
    【刷题】【dp】【背包】金明的预算
    建模结束了——5.3
    HDU
    洛谷 P2734 [USACO3.3]游戏 A Game
    洛谷 P4095 [HEOI2013]Eden 的新背包问题
    洛谷 P1156 垃圾陷阱
    洛谷 P1833 樱花
    洛谷 P3966 [TJOI2013]单词
    洛谷 P5357 【模板】AC自动机(二次加强版)
  • 原文地址:https://www.cnblogs.com/zufezzt/p/8099005.html
Copyright © 2011-2022 走看看