hdu 5878 二分+打表
来源:互联网 发布:网络教育档案存放 编辑:程序博客网 时间:2024/05/16 08:17
链接:戳这里
I Count Two Three
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
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
题意:
给出一个整数n
, 找出一个大于等于n
的最小整数m
, 使得m
可以表示为2a3b5c7d
.
思路:
预处理出所有形为2a3b5c7d
即可, 大概只有几k个.然后二分就可以了
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<string>#include<vector>#include <ctime>#include<queue>#include<set>#include<map>#include<list>#include<stack>#include<iomanip>#include<cmath>#include<bitset>#define mst(ss,b) memset((ss),(b),sizeof(ss))///#pragma comment(linker, "/STACK:102400000,102400000")typedef long long ll;typedef long double ld;#define INF (1ll<<60)-1#define Max 1e9using namespace std;int T;ll anw[1000100];ll Pow(int x,int num){ ll ans=1LL; for(int i=1;i<=num;i++) ans=ans*1LL*x; return ans;}ll n;int main(){ int cnt=0; for(int i=0;i<=31;i++){ for(int j=0;j<=19;j++){ for(int k=0;k<=12;k++){ for(int l=0;l<=11;l++){ ll tmp=Pow(2,i)*Pow(3,j); if(tmp>1e9) break; tmp*=Pow(5,k); if(tmp>1e9) break; tmp*=Pow(7,l); if(tmp>1e9) break; anw[++cnt]=tmp; } } } } sort(anw+1,anw+cnt+1); scanf("%d",&T); while(T--){ scanf("%I64d",&n); int x=lower_bound(anw+1,anw+cnt+1,n)-anw; printf("%I64d\n",anw[x]); } return 0;}
0 0
- hdu 5878 二分+打表
- hdu 5878 二分+打表
- hdu 5878 I Count Two Three【预处理打表+二分】
- hdu 1056 HangOver(暴力||打表二分)
- hdu 5179(bfs打表+二分)
- Happy 2006 素数打表+容斥原理+二分+hdu
- HDU 4151The Special Number(预处理打表+二分)
- hdu I Count Two Three(二分查找&&打表)
- hdu2446--二分搜索+打表
- HDU——1397Goldbach's Conjecture(二分查找+素数打表)
- hdu 5676 ztr loves lucky numbers(BC——暴力打表+二分查找)
- HDU——1397Goldbach's Conjecture(二分查找+素数打表)
- 2016 多校第一场 hdu 5276((线段树+暴力打表)|(RMQ + 二分))
- hdu 2136 打表
- hdu 1061打表
- HDU 1056 打表
- HDU 5867 打表
- XTU 1185 暴力打表+二分
- emacs启动的过程
- Nginx 反向代理、负载均衡、页面缓存、URL重写及读写分离详解
- ZeroC Ice3.5.1学习
- R lattice作图基本知识
- 226_Calendar方法解析
- hdu 5878 二分+打表
- Indian waale (新年快乐)主题曲 歌词
- 我人生前20年的领悟...
- C#控制台基础 获取某一文件夹下有多少个文件
- 227_Fragment的Inflater
- HDU 5884 Sort 2016 ACM/ICPC Asia Regional Qingdao Online 1007
- 2016 ACM/ICPC Asia Regional Qingdao Online hdu 5884 Sort (二分+优先队列)★
- 228_Calendar的使用
- 《只有汾阳人能听懂的四字成语》