本文共 904 字,大约阅读时间需要 3 分钟。
用set构造,优先队列和堆也能够
/*ID:kevin_s1PROG:humbleLANG:C++*/#include #include #include #include #include #include #include #include #include #include #include using namespace std;#define MAXK 110//gobal variable====int K, N;long int S[MAXK];set 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 ::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())<
转载于:https://www.cnblogs.com/cxchanpin/p/6729651.html