题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1001&cid=723

I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3582 Accepted Submission(s): 1094

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 (1≤t≤500000), the number of test cases. t test cases follow. Each test case provides one integer n (1≤n≤109).

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

题目大意:输入一个不超过10的9次方的整数n,然后输出一个最接近n且不小于n的整数同时这个数还满足

     这样的格式(2^a*3^b*5^c*7^d、  a,b,c,d可为任意非负整数)

解题思路:暴力打表   用一四重循环求出所有范围内且满足2^a*3^b*5^c*7^d格式的整数 在sort排序后二分查找。

AC代码:

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std; long long a[]; int main()
{
int t = , i, j, k, l, n; //求出所有范围内且满足2^a*3^b*5^c*7^d格式的整数
for(i = ; (long long)pow(,i) < ; i++)
for(j = ; (long long)pow(,i)*pow(,j) < ; j++)
for(k = ; (long long)pow(,i)*pow(,j)*pow(,k) < ; k++)
for(l = ; (long long)pow(,i)*pow(,j)*pow(,k)*pow(,l) < ; l++)
a[t++] = (long long)(pow(,i)*pow(,j)*pow(,k)*pow(,l)+1e-);
sort(a, a + t);
scanf("%d", &n);
while(n--)
{
scanf("%d", &l);
if(l == ) //如果是1输出它本身
printf("1\n");
else
{
i = t / ;
j = ;
k = t;
while() //二分查找
{
if(l <= a[i] && l > a[i-])
{
printf("%d\n", a[i]);
break;
}
else if(l < a[i])
{
k = i;
i = (j+i)/;
}
else
{
j = i;
i = (i+k)/;
}
}
}
}
}

注意:  打表时不能只求10^9之内的数,

   需要找超出10^9一些的数。 否则容易在边界处出错。

16年青岛网络赛 1001 I Count Two Three的更多相关文章

  1. 16年青岛网络赛 1002 Cure

    题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=723 Cure Time Limit: 30 ...

  2. HDU 6206 青岛网络赛1001 高精度 简单几何

    给出的数据1e12规模,常规判点是否在圆范围内肯定要用到半径,求得过程中无法避免溢出,因此用JAVA自带的浮点大数运算,和个ZZ一样比赛中eclipse出现问题,而且太久没写JAVA语法都不清楚变量忘 ...

  3. HDU 4759 Poker Shuffle(2013长春网络赛1001题)

    Poker Shuffle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  5. HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

    题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...

  6. HDU - 5878 2016青岛网络赛 I Count Two Three(打表+二分)

    I Count Two Three 31.1% 1000ms 32768K   I will show you the most popular board game in the Shanghai ...

  7. 2016 年青岛网络赛---Family View(AC自动机)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...

  8. 2016ACM-ICPC Qingdao Online青岛网络赛题解

    TonyFang+Sps+我=5/12 滚了个大粗 2016年9月21日16:42:36 10题完工辣 01 题意:求形同的数中大于n的最小值 题解:预处理所有的(5194个),在这里面二分 #inc ...

  9. 2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)

    2016 ACM/ICPC Asia Regional Qingdao Online(部分题解) 5878---I Count Two Three http://acm.hdu.edu.cn/show ...

随机推荐

  1. php中的json_encode()和json_decode()函数的一些说明

    一,json语法( php中的json_decode($json)中的$json要符合json语法格式 ) ① JSON可以表示三种类型的值 1,简单值.包括整型,字符串型,布尔值和null.例如:5 ...

  2. SQL语言增加、修改、删除数据的语法

    增加 insert into 表名(字段1,字段2) values ('字段1的值','字段2的值'); 修改 update 表名 set 字段1='赋予字段1的新值',字段2='赋予字段2的新值' ...

  3. Knockout学习笔记之二($root,$parent及$data的区别)

    以下是我从Google上找到的一个例子,非常生动形象,我修改了部分代码,具体内容如下: 对于$root 与$parent的区别: $root refers to the view model appl ...

  4. spark1.5 scala.collection.mutable.WrappedArray$ofRef cannot be cast to ...解决办法

    下面是我在spark user list的求助贴,很快就得到了正确回答,有遇到问题的同学解决不了也可以去上面提问. I can use it under spark1.4.1,but error on ...

  5. MyEclipse常用设置

    中文乱码设置:1.window-->preference-->general-->content type然后在<Content Types>中展开每一颗子项,并在< ...

  6. JavaWeb基础: XML基础知识

    简介 XML:可扩展标记语言,W3C指定的用于描述结构化数据的语言,XML在实际开发中,经常用作软件的配置文件,以描述程序模块之间的依赖和组合关系. XML约束:XML常常用于软件配置管理,对于软件框 ...

  7. Java Web基础:JSP基础概念

    JSP介绍 JSP全称是Java Server Pages,它和Servlet都是Sun公司定义的用于开发动态Web资源的技术,它解决了Servlet输出流排版复杂和难以维护的问题.JSP完美融合了H ...

  8. linux文件复制与权限赋值

    文件file内容赋值到file2中 1. cp  file1  file2 2. cat file1 > file2 3. cat < file1 > file2 4. dd if= ...

  9. JavaWeb chapter3 Servlet处理HTTP响应

    1.  设置响应状态行 HTTP状态码:1XX,信息性代码: 2XX,客户请求成功: 3XX,用于已经移走的资源文件,指示新的地址: 4XX,由客户端引发的错误: 5XX,由服务器端引发的错误. 2. ...

  10. C#之延迟加载

    延迟加载,亦称延迟实例化,延迟初始化等,主要表达的思想是,把对象的创建将会延迟到使用时创建,而不是在对象实例化时创建对象,即用时才加载.这种方式有助于提高于应用程序的性能,避免浪费计算,节省内存的使用 ...