| ||||||||||
| 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 | |||||||||
喜欢用STL的看过来。。用了优先队列。。按照第一个元素,小的优先。。
第二个元素是来源。。
根据来源依次向后延伸。。。
#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator