本文主要是介绍CF#278 (Div. 2) A.(暴力枚举),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
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.
解题思路:
题目大意就是给你一个a,然后问你到达最近的lucky number至少需要多少步。lucky number只要包含8即可。要求b为正数,0不行,也就是说必须从a往上走。
从a+1开始暴力枚举,对于每一个数,如果符合lucky number的条件,那么输出,否则继续+1.
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;bool check(LL x)
{if(x < 0)x = -x;while(x > 0){LL t = x % 10;if(t == 8)return true;x /= 10;}return false;
}LL min(LL a , LL b)
{return a < b ? a : b;
}int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifLL n;while(~scanf("%lld",&n)){LL cnt1 = n - 1 , cnt2 = n + 1;LL t1 = 0 , t2 = 0;while(1){t2 ++;if(check(cnt2)){break;}cnt2 ++;}printf("%lld\n",t2);}
}
这篇关于CF#278 (Div. 2) A.(暴力枚举)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!