zoukankan      html  css  js  c++  java
  • poj2545

    题意:给出三个质数,求这素因子只有这三个质数的数中第k大的。

    分析:用一个数列,第一位是1。用三个指针指向三个prime要乘的被乘数,最开始都指向1。每次取乘积最小的加入数组,并把指针后移。加入时要判断是否重复,若重复则不加入。

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    usingnamespace std;

    #define maxn 10000

    longlong p[3], n, pos[3], a[maxn];

    int main()
    {
    //freopen("t.txt", "r", stdin);
    scanf("%lld%lld%lld%lld", &p[0], &p[1], &p[2], &n);
    pos[
    0] = pos[1] = pos[2] =0;
    a[
    0] =1;
    longlong count =1;
    while (count <= n)
    {
    longlong best, besti;
    best
    = a[pos[0]] * p[0];
    besti
    =0;
    if (a[pos[1]] * p[1] < best)
    {
    best
    = a[pos[1]] * p[1];
    besti
    =1;
    }
    if (a[pos[2]] * p[2] < best)
    {
    best
    = a[pos[2]] * p[2];
    besti
    =2;
    }
    if (best != a[count -1])
    a[count
    ++] = best;
    pos[besti]
    ++;
    }
    printf(
    "%lld\n", a[n]);
    return0;
    }
  • 相关阅读:
    CSS3 --- 盒子
    CSS3 --- 伪元素
    CSS3 --- 伪类结构
    CSS3 --- 选择器
    HTML5 --- 新增表单属性
    HTML5 --- 新增标签
    CSS --- 定位
    CSS---浮动造成的影响
    CSS---盒子模型
    CSS---样式属性
  • 原文地址:https://www.cnblogs.com/rainydays/p/2050406.html
Copyright © 2011-2022 走看看