首页 > 代码库 > usaco-3.1-humble-pass
usaco-3.1-humble-pass
这个,用set:
/*ID: qq104801LANG: 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 11111int 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 TrainingGrader Results 11 users onlineCHN/5 IND/1 IRN/1 SVK/1 USA/2 YUG/1USER: cn tom [qq104801]TASK: humbleLANG: C++Compiling...Compile: OKExecuting... 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 73 5------- test 2 ----4 192 3 5 7------- test 3 ----1 202------- test 4 ----6 100002 3 5 7 11 13------- test 5 ----6 250002 3 5 7 11 13------- test 6 ----8 1000002 3 5 7 11 13 17 19------- test 7 ----7 300002 3 5 7 11 17 23------- test 8 ----7 288882 3 5 11 17 23 31------- test 9 ----1 302------- test 10 ----4 30011 17 23 31------- test 11 ----5 30011 17 19 23 31------- test 12 ----100 1000002 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 541Keep up the good work!Thanks for your submission!
usaco-3.1-humble-pass
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。