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

第一次优先队列 纠结的过了 0ms~~~~~

Posted by Heng_Xing at 2011-07-15 12:48:39 on Problem 1338
#include<iostream>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
int main (void)
{
	int n;
	int i,j,k;
	int a;
	int b[5],c;
	b[1]=2;
	b[2]=3;
	b[3]=5;
	priority_queue<int, vector<int>, greater<int> >q;
	//	priority_queue<int , vector<int>, greater<int> >qi;
	int count;
	while(scanf("%d",&n),n!=0)
	{
		q.push(b[1]);
		q.push(b[2]);
		q.push(b[3]);
		
		//	count=0;
		for(j=1;j<n-1;j++)
		{
			a=q.top();
			for(i=1;i<=3;i++)
			{
				c=a*b[i];
				if(c>0)
					q.push(c);	
				
			}
			q.pop();
			while(1)
			{
				k=q.top();
				if(k==a)
				{
					q.pop();
				}
				else
					break;
			}	
		}
		//	c=q.top();
		if(n>1)
			printf("%d\n",q.top());
		else
			printf("%d\n",1);
		
	}
	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