16年青岛网络赛 1001 I Count Two Three
题目链接: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的更多相关文章
- 16年青岛网络赛 1002 Cure
题目链接:http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1002&cid=723 Cure Time Limit: 30 ...
- HDU 6206 青岛网络赛1001 高精度 简单几何
给出的数据1e12规模,常规判点是否在圆范围内肯定要用到半径,求得过程中无法避免溢出,因此用JAVA自带的浮点大数运算,和个ZZ一样比赛中eclipse出现问题,而且太久没写JAVA语法都不清楚变量忘 ...
- HDU 4759 Poker Shuffle(2013长春网络赛1001题)
Poker Shuffle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)
Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)
题目链接 2016 青岛网络赛 Problem C 题意 给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fa ...
- 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 ...
- 2016 年青岛网络赛---Family View(AC自动机)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5880 Problem Description Steam is a digital distribut ...
- 2016ACM-ICPC Qingdao Online青岛网络赛题解
TonyFang+Sps+我=5/12 滚了个大粗 2016年9月21日16:42:36 10题完工辣 01 题意:求形同的数中大于n的最小值 题解:预处理所有的(5194个),在这里面二分 #inc ...
- 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 ...
随机推荐
- Displaying Window In Center In Oracle Forms 6i
Center window automatically in Oracle Forms 6i, use the following procedure by passing window name ...
- IOS详解TableView——内置刷新,EGO,以及搜索显示控制器
内置刷新 内置刷新是苹果IOS6以后才推出的一个API,主要是针对TableViewController增加了一个属性,refreshControl,所以如果想用这个内置下拉刷新的话,最好给你的Tab ...
- MXNet 学习 (1) --- 最易上手的深度学习开源库 --- 安装及环境搭建
安装环境:Win 10 专业版 64位 + Visual Studio 2015 Community. 记录下自己在有GPU的环境下安装配置MXNet的过程.该过程直接使用MXNet release ...
- 用 python 实现各种排序算法(转)
常见几种排序的算法: 归并排序 归并排序也称合并排序,是分治法的典型应用.分治思想是将每个问题分解成个个小问题,将每个小问题解决,然后合并. 具体的归并排序就是,将一组无序数按n/2递归分解成只有一个 ...
- SUBLIME TEXT 2 设置文件详解
SUBLIME TEXT 2 设置文件详解 Preferences.sublime-settings文件: // While you can edit this file, it’s best to ...
- 两种PHP生成二维码的方法
PHP生成二维码,个人认为最常用的有两种,1.使用google的api生成,2.使用PHP QR Code生成,两种方法生成的二维码都是很清淅的,效果不错.下面来分别说明这两种方法如何实现. 一.PH ...
- VS2010 添加服务引用以后点不出引用服务的命名空间
声明:本次我遇到的仅是这类情况中的其中一个个例,不要拘泥于些噢! 问题描述: 1.我建了一个新项目,不引用服务前是好的,可以打点点出任何已有有命名空间,但是引用服务以后就是点不出服务的命名空间. 2. ...
- BZOJ4046 [Cerc2014] Pork barre
我们把边按权值从大到小依次加入图中 如果加到边权$V$,则当前的最小生成森林中边权$v\in[V, V']$(其中$V'$是任意值)形成的森林的边权和就是对于询问$[V, V']$的答案 由于点数不多 ...
- 转: javascript实现全国城市三级联动菜单代码
<html> <head> <title>js全国城市三级联动菜单代码_B5教程网</title> <meta http-equiv=" ...
- Visual Studio 拓展插件——Image Optimizer
一句话概括效用:在Visual Studio的解决方案中,为图片或包含图片的文件夹添加右键菜单,可对图片进行压缩,无损压缩. 在VS扩展工具中安装 安装好后在VS资源管理器中选择图片右键,在右键菜单中 ...