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

      

  • 相关阅读:
    Linux文件目录结构一览表
    Linux一切皆文件(包含好处和弊端)
    Linux使用注意事项(新手必看)
    为什么建议使用虚拟机来安装Linux?
    开发中出现的问题
    为什么很多公司都在招测试开发?
    Linux cat查看文件,查找关键字(grep),统计(wc -l)
    性能测试
    Linux的感性理解
    使用Python循环插入10万数据
  • 原文地址:https://www.cnblogs.com/zufezzt/p/8099005.html
Copyright © 2011-2022 走看看