zoukankan      html  css  js  c++  java
  • UVa 11621

    称号:发现没有比给定数量少n的。只要2,3一个因素的数字组成。

    分析:数论。贪婪,分而治之。

                用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}。

                然后。每取两个指针相应元素*2和*3的值中最小的即为未找到的数字中最小的;

                注意,可能生成反复数据。不要存进去(反复数据。一定连续产生)。

    说明:打表计算。二分查询输出就可以。

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    
    using namespace std;
    
    int next[330];
    
    int bs(int key, int r)
    {
    	int l = 0,m;
    	while (l < r) {
    		m = (l+r)/2;
    		if (next[m] < key)
    			l = m+1;
    		else r = m;
    	}
    	return r;
    }
    
    int main()
    {
    	int two = 0,three = 0,count = 0;
    	next[0] = 1;
    	while (next[count] > next[count-1]) {
    		if (next[two]*2 < next[three]*3) 
    			next[++ count] = next[two ++]*2;
    		else {
    			if (next[three]*3 == next[two]*2) two ++;
    			next[++ count] = next[three ++]*3;
    		}
    	}
    	
    	int n;
    	while (cin >> n && n)
    		cout << next[bs(n, count)] << endl;
    		
    	return 0;
    }
    


    版权声明:本文博客原创文章。博客,未经同意,不得转载。

  • 相关阅读:
    FCN 分割网络详解
    ResNet 结构理解
    使用 Estimator 构建卷积神经网络
    Object Detection Review
    MP 及OMP算法解析
    Docker 使用及常用命令
    采用std::thread 替换 openmp
    模型优化,汇总
    图像几何变换
    多线程下C#如何保证线程安全?
  • 原文地址:https://www.cnblogs.com/yxwkf/p/4654688.html
Copyright © 2011-2022 走看看