题解:CF1136B Nastya Is Playing Computer Games

· · 题解

这道题比较简单,可以这么做。

  1. 拿 n 个硬币,排水孔下各有一个。

  2. 从左边往右走或从右往左走要用 (n-1) 步。

  3. 想去某一边要走离边缘近的地方, \min(n-k,k-1) 。

  4. 把所在地的石头往前扔,其余的到了那个点就往别的没有石头的井盖上扔 3+n-2 。

一共是 n+(n-1)+\min(n-k,k-1)+3+n-2 。

整理后是: 3\times n+\min(n-k,k-1) 。

#include<bits/stdc++.h>//万能头文件
using namespace std;    
int main()//主函数
{
    int n,k;
    cin>>n>>k;
    cout<<3*n+min(n-k,k-1);//数学方法

    return 0;//好习惯
}