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来看。

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

    你会知其所以然,呵呵。

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

  • 相关阅读:
    从外部访问 Template (模板)的控件、获取它的属性值
    继续聊WPF——动态数据模板
    WPF数据模板样式选择器
    深入理解正则表达式
    nssm使用,安装服务、删除服务
    Windows删除某服务
    nssm设置solr开机启动服务
    Windows下直接双击可执行的jar
    Unsupported major.minor version 52.0——解决
    js延迟2秒执行事件
  • 原文地址:https://www.cnblogs.com/dpblue/p/3963623.html
Copyright © 2011-2022 走看看