Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

最直观的优先队列算法(可惜TLE了...)

Posted by qiqilrq at 2007-05-05 11:09:32 on Problem 3104
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator