zoukankan      html  css  js  c++  java
  • 2729:Blah数集

    2729:Blah数集

    总时间限制:
    3000ms
    内存限制:
    65536kB
    描述
    大数学家高斯小时候偶然间发现一种有趣的自然数集合Blah,对于以a为基的集合Ba定义如下:
    (1) a是集合Ba的基,且a是Ba的第一个元素;
    (2)如果x在集合Ba中,则2x+1和3x+1也都在集合Ba中;
    (3)没有其他元素在集合Ba中了。
    现在小高斯想知道如果将集合Ba中元素按照升序排列,第N个元素会是多少?
    输入
    输入包括很多行,每行输入包括两个数字,集合的基a(1<=a<=50))以及所求元素序号n(1<=n<=1000000)
    输出
    对于每个输入,输出集合Ba的第n个元素值
    样例输入
    1 100
    28 5437
    
    样例输出
    418
    900585
    
     1 #include<iostream>
     2 #include<queue>
     3 #include<bits/stdc++.h>
     4 using namespace std;
     5 int tot=1;
     6 int x;
     7 int main()
     8 {
     9     int x,n;
    10     while(cin>>x&&cin>>n)
    11     {
    12     tot=1;
    13     queue<int>a;
    14     queue<int>b;    
    15     while(tot<n)
    16     {
    17         a.push(2*x+1);
    18         b.push(3*x+1);
    19         if(a.front()>b.front())
    20         {
    21             x=b.front();
    22             b.pop();
    23         }
    24         else if(a.front()<b.front())
    25         {
    26             x=a.front();
    27             a.pop();
    28         }
    29         else 
    30         {
    31             x=a.front();
    32             a.pop();
    33             b.pop();
    34         }
    35         tot++;
    36     }
    37         cout<<x<<endl;
    38     }
    39     
    40     return 0;
    41 }
  • 相关阅读:
    ::before和::after伪元素的用法
    JS中map、some、every、filter方法
    C++多线程,互斥,同步
    RAII
    Proxy 代理
    Decorator 装饰
    TCP和UDP的9个区别是什么
    谈谈自己对面向对象的理解
    C++11多线程
    std::move
  • 原文地址:https://www.cnblogs.com/zwfymqz/p/6636579.html
Copyright © 2011-2022 走看看