UVALive 2037 Digital Rivers 【打表&二分】
来源:互联网 发布:深圳软件产业基地地铁 编辑:程序博客网 时间:2024/06/05 08:53
<pre name="code" class="cpp">#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <queue>#include <stack>#include <iostream>#define MAX_N 15000#define MAX(a, b) (a > b)? a: b#define MIN(a, b) (a < b)? a: busing namespace std;int r9[MAX_N], r1[MAX_N], r3[MAX_N];//进行数字流的递推int River(int x) { int k = x; int ans = x; while (k) { ans += k%10; k /= 10; } return ans;}//进行打表void init() { r1[0] = 1, r3[0] = 3, r9[0] = 9; for (int i = 1; i < 2005; i++) { r1[i] = River(r1[i - 1]); r3[i] = River(r3[i - 1]); r9[i] = River(r9[i - 1]); }}//二分查找,节约时间int lowerbound(int x, int a[]) { int lb = -1, ub = 2000; while (ub - lb > 1) { int mid = (lb + ub)/2; if (a[mid] > x) { ub = mid; } else { lb = mid; } } return ub;}int main() { int n; init(); int m = 5; bool flag = false; int cnt = 0; while (scanf("%d", &n), n) { if (flag) printf("\n"); if (!flag ) flag = true; printf("Case #%d\n", ++cnt); //进行查找 while (true) { int a = lowerbound(n, r1); int b = lowerbound(n, r3); int c = lowerbound(n, r9); a--, b--, c--; if (n == r1[a]) { printf("first meets river 1 at %d\n", n); break; } else if(n == r3[b]) { printf("first meets river 3 at %d\n", n); break; } else if (n == r9[c]) { printf("first meets river 9 at %d\n", n); break; } n = River(n); } } return 0;}
0 0
- UVALive 2037 Digital Rivers 【打表&二分】
- 【UVALive】2037 - Digital Rivers(找规律,暴力)
- UVALive 2037 Digital River
- UVALive 4485 Crossing Rivers
- hdu1404 Digital Deletions SG打表
- Vampire Numbers - UVALive 5779 暴力打表
- UVALive 5116 Dividing Stones(dfs + 打表)
- UVALive 6934 Good morning! 打表判断
- UVALive - 6269 Digital Clock 模拟
- ZOJ.3131 Digital Clock【打表】 2015/10/11
- hdu 5878 二分+打表
- hdu 5878 二分+打表
- hdu2446--二分搜索+打表
- UVALive 4854 A Digital Satire of Digital Age
- UVALive 4854 A Digital Satire of Digital Age
- UVALive 6269 Digital Clock --枚举,模拟
- UVALIVE 3635 Pie 二分
- UVALive 6144 Radiation 二分
- 统计学习方法笔记(四)
- facebook-pop开源动画框架
- iOS UILabel 文字竖排显示
- Java Web开发框架对比—Part2—框架复杂性
- jzoj 1415. 【2012.04.14普及组】最短距离
- UVALive 2037 Digital Rivers 【打表&二分】
- Matlab2015a调用Python程序
- POJ 1017 Packets(简单贪心)
- 第3条:避免创建不必要的对象
- Autolayout03 - 视图居中
- iOS滚珠菜单动效
- .Net WebApi接口集成Swagger进行美化和调试教程
- 农业垂直搜索引擎四》文本处理模块的设计与实现
- Android Databinding 从入门到转行(一)初步介绍