Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
最直观的优先队列算法(可惜TLE了...)#include <iostream> #include <queue> using namespace std; const int maxn=100001; int A[maxn], N, K; int main() { priority_queue<int> Qu; while(scanf("%d", &N)!=EOF) { for(int i=1; i<=N; i++) { scanf("%d", A+i); Qu.push(A[i]); } scanf("%d", &K); K--; if(K==0) {cout<<Qu.top()<<endl; return 0;} int tm=0; while(Qu.top() > tm) { Qu.push(Qu.top()-K); Qu.pop(); tm++; } cout<<tm<<endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator