zoukankan      html  css  js  c++  java
  • usaco-3.1-humble-pass

    这个,用set:

    /*
    ID: qq104801
    LANG: C++
    TASK: humble
    */
    
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #include <vector>
    #include <list>
    #include <set>
    #include <queue>
    #include <cstdio>
    #include <algorithm>
    #include <cmath>
    
    using namespace std;
    
    #define NMAX 11111
    int k,n;
    int h[101];
    set<long int> ss;
    
    void test()
    {    
        freopen("humble.in","r",stdin);
        freopen("humble.out","w",stdout);
        cin>>k>>n;
        for(int i=1;i<=k;i++)
        {
            cin>>h[i];
            ss.insert(h[i]);
        }
        for(int i=1;i<=k;i++)
        {
            set<long int>::iterator it=ss.begin();
            while(true)
            {
                long int temp=(*it)*h[i];
                if(temp<0)break;
                if(ss.size()>n)
                {
                    ss.erase(--ss.end());
                    if(temp>(*(--ss.end())))break;
                }
                ss.insert(temp);
                it++;
            }
        }
        cout<<*(--ss.end())<<endl;      
    }
    
    int main () 
    {        
        test();        
        return 0;
    }

    test data:

    USACO Training
    Grader Results     
    11 users online
    CHN/5 IND/1 IRN/1 SVK/1 USA/2 YUG/1
    
    USER: cn tom [qq104801]
    TASK: humble
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.005 secs, 3508 KB]
       Test 2: TEST OK [0.003 secs, 3508 KB]
       Test 3: TEST OK [0.003 secs, 3508 KB]
       Test 4: TEST OK [0.019 secs, 3640 KB]
       Test 5: TEST OK [0.027 secs, 4036 KB]
       Test 6: TEST OK [0.103 secs, 5752 KB]
       Test 7: TEST OK [0.041 secs, 4168 KB]
       Test 8: TEST OK [0.035 secs, 4168 KB]
       Test 9: TEST OK [0.005 secs, 3508 KB]
       Test 10: TEST OK [0.005 secs, 3508 KB]
       Test 11: TEST OK [0.005 secs, 3508 KB]
       Test 12: TEST OK [0.240 secs, 5752 KB]
    
    All tests OK.
    
    YOUR PROGRAM ('humble') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
    
    Here are the test data inputs:
    
    ------- test 1 ----
    2 7
    3 5
    ------- test 2 ----
    4 19
    2 3 5 7
    ------- test 3 ----
    1 20
    2
    ------- test 4 ----
    6 10000
    2 3 5 7 11 13
    ------- test 5 ----
    6 25000
    2 3 5 7 11 13
    ------- test 6 ----
    8 100000
    2 3 5 7 11 13 17 19
    ------- test 7 ----
    7 30000
    2 3 5 7 11 17 23
    ------- test 8 ----
    7 28888
    2 3 5 11 17 23 31
    ------- test 9 ----
    1 30
    2
    ------- test 10 ----
    4 300
    11 17 23 31
    ------- test 11 ----
    5 300
    11 17 19 23 31
    ------- test 12 ----
    100 100000
    2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521 523 541
    
    Keep up the good work!
    Thanks for your submission!
    /***********************************************

    看书看原版,原汁原味。

    不会英文?没关系,硬着头皮看下去慢慢熟练,才会有真正收获。

    没有原书,也要网上找PDF来看。

    网上的原版资料多了去了,下载东西也到原始下载点去看看。

    你会知其所以然,呵呵。

    ***********************************************/

  • 相关阅读:
    获取网页数据
    追踪公式引用的单元格
    loadRunner函数之lr_set_debug_message
    Python爬虫之抓取豆瓣影评数据
    Python爬虫之抓图
    loadRunner函数之web_add_header
    JVM是如何处理异常的
    1. JVM内存区块
    JVM-JVM是如何执行方法调用的
    JVM-内部类分析
  • 原文地址:https://www.cnblogs.com/dpblue/p/3963623.html
Copyright © 2011-2022 走看看