I Count Two Three---hdu5878(打表+二分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878
题意:找到第一个>=n的数x, 满足 x = 2a3b5c7d;n<=1e9;
打表找到10e9以内的所有符合条件的数,然后二分找到即可;
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<set>
using namespace std;
#define met(a, b) memset(a, b, sizeof(a))
#define N 100005
#define INF 0x3f3f3f3f
typedef long long LL;
const LL MAX = 1e9+; int cnt = ;
LL f[N], a2[], a3[], a5[], a7[]; void Init()
{
int P, Q, I, J;
a2[] = a3[] = a5[] = a7[] = ; for(int i=; a2[i-]*<=MAX; i++, I=i) a2[i] = a2[i-]*;
for(int i=; a3[i-]*<=MAX; i++, J=i) a3[i] = a3[i-]*;
for(int i=; a5[i-]*<=MAX; i++, P=i) a5[i] = a5[i-]*;
for(int i=; a7[i-]*<=MAX; i++, Q=i) a7[i] = a7[i-]*; for(int i=; i<I; i++)
{
for(int j=; j<J; j++)
if(MAX/a2[i] >= a3[j])
for(int p=; p<P; p++)
if(MAX/(a2[i]*a3[j]) >= a5[p])
for(int q=; q<Q; q++)
{
if(MAX/(a2[i]*a3[j]*a5[p]) >= a7[q])
f[cnt++] = a2[i]*a3[j]*a5[p]*a7[q];
}
}
sort(f, f+cnt);
} int main()
{
Init(); int T; LL n;
scanf("%d", &T);
while(T--)
{
scanf("%I64d", &n);
int pos = upper_bound(f, f+cnt, n) - f;
if(f[pos-] == n) pos--;
printf("%I64d\n", f[pos]);
}
return ;
}
I Count Two Three---hdu5878(打表+二分)的更多相关文章
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- 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 ...
- HDU 5878 I Count Two Three (打表+二分查找) -2016 ICPC 青岛赛区网络赛
题目链接 题意:给定一个数n,求大于n的第一个只包含2357四个因子的数(但是不能不包含其中任意一种),求这个数. 题解:打表+二分即可. #include <iostream> #inc ...
- 「ZJOI2018」胖(ST表+二分)
「ZJOI2018」胖(ST表+二分) 不开 \(O_2\) 又没卡过去是种怎么体验... 这可能是 \(ZJOI2018\) 最简单的一题了...我都能 \(A\)... 首先我们发现这个奇怪的图每 ...
- I Count Two Three(打表+排序+二分查找)
I Count Two Three 二分查找用lower_bound 这道题用cin,cout会超时... AC代码: /* */ # include <iostream> # inclu ...
- [LeetCode] #1# Two Sum : 数组/哈希表/二分查找/双指针
一. 题目 1. Two SumTotal Accepted: 241484 Total Submissions: 1005339 Difficulty: Easy Given an array of ...
- HDU5878(打表)
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- GCD(st表+二分)
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- 【BZOJ-4310】跳蚤 后缀数组 + ST表 + 二分
4310: 跳蚤 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 180 Solved: 83[Submit][Status][Discuss] De ...
随机推荐
- object-c 协议和委托
协议相当于接口 委托相当于帮助实现其它类的功能 object-c提供的协议机制,一个类可以实现多个协议,从而感觉上像多继承一样
- 【POJ】1113 Wall(凸包)
http://poj.org/problem?id=1113 答案是凸包周长+半径为l的圆的周长... 证明?这是个坑.. #include <cstdio> #include <c ...
- java定时器的使用
定时器类Timer在java.util包中.使用时,先实例化,然后使用实例的schedule(TimerTask task, long delay)方法,设定指定的任务task在指定的延迟delay后 ...
- JBPM4.4+SSH 整合配置及完整实例
整合jBPM4.4+ssh过程(spring接管struts2和hibernate,例中都整合在application.xml中,没有单独的jbpm.hibernate.cfg.xml): 1.在se ...
- 兼容ie[6-9]、火狐、Chrome、opera、maxthon3、360浏览器的js本地图片预览
html代码: <div id="divPreview"> <img id="imgHeadPhoto" src="Images/H ...
- SSH整合配置二级缓存
一.了解 Hibernate的session提供了一级缓存,每个session,对同一个id进行两次load,不会发送两条sql给数据库,但session关闭时,一级缓存失效. 二级缓存是Sessio ...
- HTML5 video 视频标签全属性详解
现在如果要在页面中使用video标签,需要考虑三种情况,支持Ogg Theora或者VP8(如果这玩意儿没出事的话)的(Opera.Mozilla.Chrome),支持H.264的(Safari.IE ...
- JavaScript验证函数大全
1. 长度限制 <script> function test() { if(document.a.b.value.length>50) { alert("不能超过50个字符 ...
- 多个mysql增加多个服务
//mysql安装目录 mysqld --install mysqld --remove mysql5.5 mysqld --remove mysql5.5 C:\Program Files\MySQ ...
- Css - 基础的css阴影效果
基本的css3阴影效果 width:971px; height:608px; border:1px solid #ccc; background-color:#fff; filter:progid:D ...