社区讨论

思路乱套

P1145[CERC1995] 约瑟夫参与者 4已保存回复 3

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
3 条
当前快照
1 份
快照标识符
@lyl91wt1
此快照首次捕获于
2024/07/14 15:44
2 年前
此快照最后确认于
2024/07/14 16:59
2 年前
查看原帖
代码思路已经乱了,求调:
CPP
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define coutdouble(a, b) cout << fixed << setprecision(a) << (b)
#define ll long long
#define endl '\n'

using namespace std;

const int N = 1e5 + 5;
const int INF = 0x3f3f3f;
const int INFS = -0x3f3f3f;

int k, m = 0;

void cnt(int x, int num, int bed) // x:第几个人 num:找最小的m,bad:坏人数量
{
    if (bed == 0) // 如果坏人死光,更新m
    {
        m = num;
        return ;
    }
    else
    {
        if (x > k * 2) x = 1; // 如果数完一圈,回到第一人
        if (x > k) cnt(x++, num, bed--); // 如果当前的人是坏人(前k人是好人,编号大于k的就是坏人)
        else cnt(1, num++, k); // 如果当前的人是好人(编号小于等于k),重来
    }
}

void solve()
{
    cin >> k;
    cnt(1, 1, k);
    cout << m << endl;
}

signed main()
{
    // freopen("../in_out/in.txt", "r", stdin);
    // freopen("../in_out/out.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);  // 关闭同步流

    int t = 1;
    // cin>>t;
    while (t--)
    {
        solve();
    }

    return 0;
}

回复

3 条回复,欢迎继续交流。

正在加载回复...