HDU-5878-I Count Two Three-预处理+二分
来源:互联网 发布:java后端工程师 编辑:程序博客网 时间:2024/05/22 03:47
题目链接
题意就是给定一个n,求不小于n的一个只有2,3,5,7为因子构成的数(包括1)
思路预处理出所有的满足的数,然后二分一下就好了。
#include<bits/stdc++.h>#define maxn 1000000000using namespace std;int x[5]={1,2,3,5,7};int x2[5]={1,30,19,13,11};long long a[5555];int tt=0;void dfs(int pos,long long ans) { if(pos==5) { a[++tt]=ans; return; } for(int i=0;i<=x2[pos];i++) { if(i!=0) ans*=x[pos]; if(ans>maxn) { break; } dfs(pos+1,ans); }}int main(){ dfs(1,1); long long n; sort(a+1,a+tt+1); int t; scanf("%d",&t); while(t--) { scanf("%lld",&n); int head=1,wei=tt; while(head<wei) { int mid=(head+wei)/2; if(a[mid]<n) { head=mid+1; } else { wei=mid; } } printf("%lld\n",a[head]); } return 0;}
0 0
- HDU 5878 I Count Two Three (DFS预处理 + 二分)
- hdu 5878 I Count Two Three【预处理打表+二分】
- 【HDU 5878】I Count Two Three(预处理+二分)
- HDU-5878-I Count Two Three-预处理+二分
- HDU 5878 I Count Two Three (dfs+二分)
- hdu 5878 I Count Two Three(二分)
- HDU 5878 I Count Two Three(打表加二分)
- hdu 5878 I Count Two Three 丑数 二分
- hdu 5878 I Count Two Three
- 【30.53%】【hdu 5878】I Count Two Three
- HDU 5878 I Count Two Three .
- HDU 5878 - I Count Two Three
- HDU 5878 I Count Two Three
- HDU-5878-I Count Two Three
- hdu I Count Two Three(二分查找&&打表)
- 5878 I Count Two Three
- HDU 5878 I Count Two Three 2016青岛网赛
- hdu 5878 I Count Two Three 丑数
- Quick-cocos2d-x游戏数据存储
- 读取不同格式文件的两种方式
- java编程思想 第四版 第七章读书笔记
- 235_自定义抽签器一
- (kuangbin DFS)棋盘问题
- HDU-5878-I Count Two Three-预处理+二分
- leetcode 373. Find K Pairs with Smallest Sums
- topcoder客户端下载地址
- Java IO字符流写文件的总结
- Brothers【NOIP2016提高A组模拟9.9】
- 236_自定义抽签器二
- 将一个字符串数组中的字母按照以下规则排列
- 237_自定义抽签器三
- 什么是Zero-Copy?