题解 | #Energy Synergy Matrix#

Energy Synergy Matrix

https://ac.nowcoder.com/acm/contest/120563/F

本题主要在于必须要留下可行的路,因此每一个路障,可以确定三个格子为路
小红想要最优解,需要少拐,因此只需要在上一步的路上延长三格,对应的障碍位置放上障碍即可
小紫想要最优解,需要多拐,因此只需要直接在当前路上放上障碍强制拐弯即可
观察发现,每5个格子使得多拐一次,可以得到答案为n+(n/5)-1
#include<bits/stdc++.h>
#define mk std::make_pair

using namespace std;
using pii = pair<int, int>;

const int N = 2e5+7;

typedef long long LL;

void solve()
{
    int n;
    cin >> n;
    cout << (n-1) + (n/5) << '\n';
}

int main()
{
    int T = 1;
    cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务