[ACM]codeorces 488A Giga Tower (暴力枚举)
来源:互联网 发布:河北工程大学网络 编辑:程序博客网 时间:2024/05/21 15:23
Giga Tower is the tallest and deepest building in Cyberland. There are 17 777 777 777 floors, numbered from - 8 888 888 888 to 8 888 888 888. In particular, there is floor 0 between floor - 1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view.
In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8 888 888 888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8, - 180, 808 are all lucky while42, - 10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?).
Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered a. He wants to find the minimum positive integer b, such that, if he walks b floors higher, he will arrive at a floor with a lucky number.
The only line of input contains an integer a ( - 109 ≤ a ≤ 109).
Print the minimum b in a line.
179
1
-1
9
18
10
For the first sample, he has to arrive at the floor numbered 180.
For the second sample, he will arrive at 8.
Note that b should be positive, so the answer for the third sample is 10, not 0.
题意为有一座高塔,从-888 888 888 8 层到 888 888 888 8层,中间也有第0层,且楼层数带有 数字8 的楼层为幸运楼层,比如8,1008, 888等。假设一个人站在第a层(-10^9<=a<=10^9) ,问他最少向上爬多少层,才能到达幸运楼层,答案为正整数。
这个题目猛一看数据范围那么大,被吓了一跳,后来又把问题想复杂了。。。。 一个数有没有8,加多少才能保证有8,其实只要关心 个位和十位就好了,只要保证这两位至少有1个8就可以了,高位根本就不用管,所以暴力枚举的话,顶多超不过100。所以只要a不断增加1,增加一次判断一次,只要含有8,就跳出循环。
代码:
#include <iostream>#include <cmath>using namespace std;bool ok(int a){ if(a<0) a=-a; while(a) { if(a%10==8) return true; a/=10; } return false;}int a;int main(){ while(cin>>a) { int ans=0; while(1) { a++; ans++; if(ok(a)) break; } cout<<ans<<endl; } return 0;}
- [ACM]codeorces 488A Giga Tower (暴力枚举)
- Codeforces 488A Giga Tower
- Codeforces 488A Giga Tower(水)
- A. Giga Tower
- Codeforces Round #278 (Div. 2) A Giga Tower
- Codeforces Round #278 (Div. 2)---A. Giga Tower
- Codeforces Round #278 (Div. 2) A. Giga Tower(水题)
- ACM--枚举暴力--HDOJ 1017--A Mathematical Curiosity--水
- CF #633A(暴力枚举)
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
- [ACM] ZOJ 3816 Generalized Palindromic Number (DFS,暴力枚举)
- Codeforce 890A ACM ICPC(枚举)
- A - Stones I (暴力枚举)
- codeforces 577A(暴力枚举)
- HDU ACM 4414 Finding crosses 暴力枚举
- HDU ACM 5254 棋盘占领->暴力枚举
- ACM 暴力枚举 Meeting with Aliens
- Codeforces 425A Sereja and Swaps(暴力枚举)
- 【游戏设计电子书】《游戏是什么》 By:邪让多杰
- 多线程
- SQLite的SQL语法
- Android http post 中文乱码问题的解决
- VMware 中安装Ubuntu后忘记root密码
- [ACM]codeorces 488A Giga Tower (暴力枚举)
- JSON解析实例——使用Json-lib
- 设计模式之禅单一职责原则
- java length()的返回值
- 好的网站链接或文章链接(四)
- MySQL的全文本搜索
- 线段树的实现及其经典用法(C++实现)
- 技术人的生活一样很重要
- [leetcode]Merge Intervals