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

喜欢用STL的看过来。。

Posted by rain_bow at 2009-08-28 21:05:33 on Problem 1338
用了优先队列。。按照第一个元素,小的优先。。
第二个元素是来源。。
根据来源依次向后延伸。。。

#include<iostream>
#include<queue>
using namespace std;

typedef pair<__int64 ,int > Node;
__int64 p[1501];
int main()
{
	priority_queue<Node,vector<Node>,greater<Node> > joy_p;
	int i;
	Node tmp;

	joy_p.push( make_pair(1,2) );
	for(i=1;i<=1500;i++)
	{
		tmp=joy_p.top();
		joy_p.pop();
		switch(tmp.second)
		{
		case 2: joy_p.push( make_pair(tmp.first*2,2) );
		case 3: joy_p.push( make_pair(tmp.first*3,3) );
		case 5: joy_p.push( make_pair(tmp.first*5,5) );
		}
		p[i]=tmp.first;
	}
	int n;
	while(scanf("%d",&n)&&n)
	{
		printf("%I64d\n",p[n]);
	}
	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