题目连接:
https://vjudge.net/problem/1502082/origin
这一题第一眼看过去貌似是模拟,但是根据其范围是1e9可以知道,如果暴力解基本上是不可能的(不排除大佬级优化)
于是对1---9进行计算可以得到如下结果:
1 --- 1
2 --- 2
3 --- 2
4 --- 3
5 --- 3
6 --- 4
7 --- 4
8 --- 5
9 --- 5
故而有得到规律 n --- n/2+1
根据规律得到代码:

#include <iostream> #include <cstdio> using namespace std; int main() { int n; scanf("%d", &n); int ans = n/2+1; printf("%d ", ans); }
如有不懂欢迎评论~