You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Codeforces题目A-I Wanna Be the Guy测试用例27错误求助

分析Codeforces题目“A-I Wanna Be the Guy”测试用例错误原因

你的代码问题出在误把每行开头的关卡数量值当成了关卡编号插入集合,导致集合元素数量判断错误。

看测试用例的输入:

3
1 2
2 2 3

你的代码会依次读取到3、1、2、2、2、3,其中1和2(两行开头的计数数字)因为不等于0,都被插入了set。最终set里的元素是{1,2,3},大小等于n=3,所以错误输出了"I become the guy."。但实际上玩家1只能通关关卡2,玩家2能通关2、3,缺少关卡1,正确输出应该是"Oh, my keyboard!"。

修正方案

正确的输入逻辑是:读取总关卡数n后,先读取每行开头的计数(p和q),然后只读取对应数量的关卡编号加入集合,跳过计数数字。

修正后的代码示例:

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    set<int> s;
    
    // 处理第一个玩家的通关关卡
    int p;
    cin >> p;
    for (int i = 0; i < p; ++i) {
        int x;
        cin >> x;
        s.insert(x);
    }
    
    // 处理第二个玩家的通关关卡
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int x;
        cin >> x;
        s.insert(x);
    }
    
    cout << (s.size() == n ? "I become the guy." : "Oh, my keyboard!") << endl;
    return 0;
}

内容的提问来源于stack exchange,提问作者young coder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 05:07:23