hdu 5878 I Count Two Three 丑数
来源:互联网 发布:the weeknd earned it 编辑:程序博客网 时间:2024/05/21 20:55
题意:求第一个大于等于n的最小丑数
思路:就是简单的单纯模拟,然后二分求出来,看了下,按照题目范围应该只有5195个丑数。有个注意的地方,判断等于那里不能写成else if,因为这样会造成大量重复的丑数,直接爆掉
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878
#include <cstdio>#include <cstring>#include <vector>using namespace std;long long ans[100000];int cnt;long long Min(long long a, long long b, long long c, long long d){ long long temp1 = a < b ? a : b; long long temp2 = c < d ? c : d; return temp1 < temp2 ? temp1 : temp2;}void init(){ cnt = 1; int a1 = 0, a2 = 0, a3 = 0, a4 = 0; ans[0] = 1; while(true) { long long temp = Min(ans[a1] * 2, ans[a2] * 3, ans[a3] * 5, ans[a4] * 7); ans[cnt++] = temp; if(temp == ans[a1] * 2) a1++; if(temp == ans[a2] * 3) a2++;//不能写成else if if(temp == ans[a3] * 5) a3++; if(temp == ans[a4] * 7) a4++; if(ans[cnt - 1] > 1000000000) break; }}int main(){ init(); int t; scanf("%d", &t); while(t--) { long long n; scanf("%I64d", &n); int pos = lower_bound(ans, ans + cnt, n) - ans; printf("%I64d\n", ans[pos]); } return 0;}
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878
0 0
- 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
- 2016ICPC网赛青岛站1001 I Count Two Three丑数的应用求解
- HDU 5878-I Count Two Three(可被2 3 5 7整除的数)
- 5878 I Count Two Three
- HDU 5878 I Count Two Three (dfs+二分)
- hdu 5878 I Count Two Three(二分)
- HDU 5878 I Count Two Three 2016青岛网赛
- 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(预处理+二分)
- WebService(1)_WebService概述
- hdu5878 2016青岛网络赛-打表+二分
- 只是不想生活在最底层
- phpstorm 2016.2 的最新破解方法(截止2016-8-1)
- WebService(2)_WSDL文档
- hdu 5878 I Count Two Three 丑数
- hdu 5884 Sort k叉哈夫曼树+双队列优化
- Leetcode :3. Longest Substring Without Repeating Characters
- 第3周项目3-求集合并集
- 排序算法之一--直接插入排序
- 在单链表上实现插入排序
- 第三周 项目四——顺序表应用(2)
- <Pro ASP.NET MVC 5> - Note02
- poj3686 The Windy's(拆点,费用流,好题)