Codeforces I Wanna Be the Guy 题解

这道题非常简单,有两种做法:
1. 用一个数组标记是不是每个关卡小X或小Y都可以通过
1. 用set储存小X和小Y能够通过的关卡(set有去重功能),最后判断set的长度是否等于n

因为楼上已经有第一种做法的题解了,所以,我用第二种方法。

set具体用法可以上百度


代码如下(C++):

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

int main() {
    int n;
    set<int> s;
    cin>>n;
    int p,q;
    cin>>p;
    for(int i=1;i<=p;i++) {
        int x;
        cin>>x;
        s.insert(x);//将输入的关卡存入set
    }
    cin>>q;
    for(int i=1;i<=q;i++) {
        int x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==n) cout<<"I become the guy."<<endl;//能够完成游戏
    else cout<<"Oh, my keyboard!"<<endl;//不能
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Ryan-juruo/p/11627447.html