USACO humble
USACO
2023-09-11 14:14:10 时间
用set构造,优先队列和堆也能够
/* ID:kevin_s1 PROG:humble LANG:C++ */ #include <iostream> #include <cstdio> #include <string> #include <cstring> #include <vector> #include <map> #include <set> #include <algorithm> #include <cstdlib> #include <list> #include <cmath> using namespace std; #define MAXK 110 //gobal variable==== int K, N; long int S[MAXK]; set<long int> humble; //================== //function========== //================== int main(){ freopen("humble.in","r",stdin); freopen("humble.out","w",stdout); cin>>K>>N; for(int i = 1; i <= K; i++){ cin>>S[i]; humble.insert(S[i]); } for(int i = 1; i <= K; i++){ set<long int>::iterator iter = humble.begin(); while(1){ long int tmp = (*iter) * S[i]; if(tmp < 0) break; if(humble.size() > N){ humble.erase(--humble.end()); if(tmp > (*(--humble.end()))) break; } humble.insert(tmp); iter++; } } cout<< *(--humble.end())<<endl; return 0; }
相关文章
- 【USACO 2019 February Bronze】Measuring Traffic 题解
- Java实现【USACO】1.1.2 贪婪的礼物送礼者 Greedy Gift Givers
- [usaco] 5.4.4 Betsy's Tour
- [usaco] 4.4.1PROB Shuttle Puzzle
- [usaco]单源最短路径:3.3.5 Sweet Butter
- [usaco]Bessie Come Home
- [usaco] Cow Pedigrees
- [usaco][舞会灯] party lamps
- 【usaco】 checker
- 刷题记录:牛客[USACO 2010 Feb G]Slowing down
- 刷题记录:牛客NC25084[USACO 2006 Nov S]Bad Hair Day
- 刷题记录:牛客NC24017[USACO 2016 Jan S]Angry Cows
- 刷题记录:牛客NC25080[USACO 2007 Ope S]Catch That Cow
- 刷题记录:牛客NC24755[USACO 2010 Dec S]Apple Delivery