您的位置:首页 > 其它

hdu 3199 Hamming Problem

2015-08-07 22:01 351 查看
题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=3199

解题思路:

虽然数很大,但是并没有超过long long 的最大数,所以还是直接按照丑数的求法来就行了。。。

AC代码:

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

typedef long long ll;
typedef pair<ll,int> node_type;
ll result;

int main(){
    //cout<<(numeric_limits<long long>::max)()<<endl;
    ll p1,p2,p3,n;
    while(~scanf("%lld%lld%lld%lld",&p1,&p2,&p3,&n)){
        priority_queue<node_type,vector<node_type>,greater<node_type> > q;
        q.push(make_pair(1,p1));
        for(int i = 1; i <= n+1; i++){
            node_type node  = q.top();
            q.pop();
            if(node.second == p1){
                q.push(make_pair(node.first*p1,p1));
                q.push(make_pair(node.first*p2,p2));
                q.push(make_pair(node.first*p3,p3));
            }
            else if(node.second == p2){
                q.push(make_pair(node.first*p2,p2));
                q.push(make_pair(node.first*p3,p3));
            }
            else
                q.push(make_pair(node.first*p3,p3));
            result = node.first;
        }
        printf("%lld\n",result);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: