一道有意思的找规律题目 --- CodeForces - 964A

题目连接:

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\n", ans);
}
View Code

如有不懂欢迎评论~

猜你喜欢

转载自www.cnblogs.com/mpeter/p/10288195.html