2016 ACM/ICPC 青岛网赛 1001(预处理+二分)
2017-09-10 21:40
211 查看
I Count Two Three
题意:求能用2^a*3^b*5^c*7^d表示的大于等于n的值,其中a,b,c,d均为非负整数。
我们可以先把能用2^a*3^b*5^c*7^d表示的数打表,,然后二分即可。n的最大值为10^9,估算一下数组开到6000即可。
代码:
题意:求能用2^a*3^b*5^c*7^d表示的大于等于n的值,其中a,b,c,d均为非负整数。
我们可以先把能用2^a*3^b*5^c*7^d表示的数打表,,然后二分即可。n的最大值为10^9,估算一下数组开到6000即可。
代码:
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int max_n=6000; const int inf=1000000000; int b[max_n]={1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int p[4]={2, 3, 5, 7}; int n; void init() { int crt; for (int i=10;i<max_n;i++) { crt=i-1; b[i]=inf; for (int j=0;j<4;j++) { while(b[crt-1]*p[j]>b[i-1]) crt--; b[i]=min(b[i],b[crt]*p[j]); } } } int main() { init(); int t; cin >> t; while (t--) { scanf("%d",&n); int res=*lower_bound(b,b+max_n,n); printf("%d\n",res); } }
相关文章推荐
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
- 2016 ACM/ICPC 青岛区域赛网络赛 1001 I Count Two Three(打表+二分)
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001 I Count Two Three(打表+二分搜索)
- HDU 5954 Do not pour out 积分 二分 — 2016ACM-ICPC亚洲区沈阳站
- 2016ACM/ICPC Shengyang Online-1001 Resident Evil
- 2016 ACM/ICPC Asia Regional Qingdao Online 青岛网赛
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001
- hdu--5878(hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001))
- hdu 5892 List wants to travel 2016ACM/ICPC沈阳赛区网络赛1001
- 【二分】NEERC15 L Landscape Improved(2015-2016 ACM-ICPC)(Codeforces GYM 100851)
- 【2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest J】【二分答案+multiset】Journey to the “The World’
- 2015-2016 ACM-ICPC, NEERC, Southern Subregional Contest F. Gourmet and Banquet(贪心+二分)
- hdu 5878 I Count Two Three 2016ACM/ICPC青岛赛区网络赛1001
- HDU 5954 Do not pour out 积分 二分 — 2016ACM-ICPC亚洲区沈阳站
- hdu5971 Wrestling Match(染色法判二分) 2016ACM/ICPC亚洲区大连站
- [Contests]2016 ACM/ICPC Asia Regional Qingdao Online(1001/2/4/5/6)
- HDU 5953 Game of Taking Stones(威佐夫博弈+高精度+二分)——The 2016 ACM-ICPC Asia Dalian Regional Contest
- 2015-2016 ACM-ICPC, NEERC, Northern Subregional Contest Problem J 【二分+DP+单调队列】
- 2016 ACM-ICPC 亚洲区域赛北京站E题 What a Ridiculous Election (BFS预处理)
- 2016 ACM/ICPC Asia Regional Dalian Online 1008 Function 二分+RMQ