zoukankan      html  css  js  c++  java
  • 【30.53%】【hdu 5878】I Count Two Three

    Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 537    Accepted Submission(s): 271


    Problem Description
    I will show you the most popular board game in the Shanghai Ingress Resistance Team.
    It all started several months ago.
    We found out the home address of the enlightened agent Icount2three and decided to draw him out.
    Millions of missiles were detonated, but some of them failed.

    After the event, we analysed the laws of failed attacks.
    It's interesting that the i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.

    At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
    A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.
     

    Input
    The first line of input contains an integer t (1t500000), the number of test cases. t test cases follow. Each test case provides one integer n (1n109).
     

    Output
    For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than n.
     

    Sample Input
    10 1 11 13 123 1234 12345 123456 1234567 12345678 123456789
     

    Sample Output
    1 12 14 125 1250 12348 123480 1234800 12348000 123480000
     

    Source

    【题解】

    10^9用2乘就是2^30左右。用3 是3^19,又是5^13,又是7^11;

    然后30*19*13*11不会很大!

    注意2^0,3^0。。。

    然后枚举2,3,5,7的指数。得到一个数字。

    我是觉得不会有重复的数字。

    但是有也没关系。lower_bound的功能足够解决这道题。

    【代码】

    #include <cstdio>
    #include <algorithm>
    
    
    const long long num[5] = { 0,2,3,5,7 };
    const int limit[5] = { 0,30,19,13,11 };
    const long long max = 1000000000;
    
    long long a[5] = { 0 };
    long long pre[5][31];
    long long tt = 1;
    long long b[90000];
    
    int t, n = 0;
    //max==9
    
    void dfs(int now)//dfs枚举质因子的指数
    {
    	if (tt > max)
    		return;
    	if (now == 5)
    	{
    		n++;
    		b[n] = tt;
    		return;
    	}
    	for (int i = 0; i <= limit[now]; i++)
    	{
    		long long kk = tt;
    		tt *= pre[now][i];
    		dfs(now + 1);
    		tt = kk;
    	}
    }
    
    int main()
    {
    	//freopen("F:\rush.txt", "r", stdin);
    	//freopen("F:\rush_out.txt", "w", stdout);
    	for (int i = 1; i <= 4; i++)
    		pre[i][0] = 1;
    	for (int i = 1; i <= 4; i++)
    	{
    		for (int j = 1; j <= limit[i]; j++)//预处理出2^x,3^y...
    			pre[i][j] = pre[i][j - 1] * num[i];
    	}
    	dfs(1);
    	std::sort(b + 1, b + 1 + n);//排序。之后才能用lower_bound;
    	scanf("%d", &t);
    	long long query;
    	for (int i = 1; i <= t; i++)
    	{
    		scanf("%I64d", &query);
    		printf("%I64d
    ", b[std::lower_bound(b + 1, b + 1 + n, query) - b]);
    	}
    	return 0;
    }


  • 相关阅读:
    SpringBoot整合Swagger-ui
    SpringBoot整合Mybatis之Annotation
    Java的四层结构dto、dao、service、controller
    spring boot 项目开发常用目录结构
    Ubuntu Docker-ce安装
    SQL,NoSQL和NewSQL
    Spring常用注解
    JAVA复习重点知识
    谷歌浏览器收藏内容备份
    网线连上显示无网络连接
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7632237.html
Copyright © 2011-2022 走看看