题解:P17655 [IO 2025 #1] 丝绸阶梯

· · 题解

思路解析:

注意到 n 高达 10^{12} 所以思考结论。先把样例画出来。 为什么这个地图是最优的呢?因为从 n 右上角走到 n+1 的右上角最少转 3 次弯,从原点到第一个右上角只有转 1 次弯。所以这个路径是最优的。所以结论就是 (n-1) \times 3 + 1。

代码展示:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1010;

int a[N],n;

signed main(){
    ios::sync_with_stdio(false),cin.tie(nullptr);
    cin>>n;
    cout<<(n-1)*3+1;//结论
    return 0;
}