题解 | #小球投盒#

小球投盒

https://www.nowcoder.com/practice/e0e8a6f2ba7747b5a9f8a8dc6fa3e9f1

#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <numeric>
#include <ctime>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
const ll N = 1e5 + 5, mod = 1e9 + 7, inf = 2e18;

int n, m;

void solve() {
    cin >> n >> m;

    set<int>st, st2;

    for (int i = 1; i <= m; i++) {
        int op, x;
        cin >> op >> x;
        if (op == 1) {
            st.insert(x);
            if (st.size() >= n || st2.find(x) != st2.end()) {
                cout << i;
                return ;
            }
        } else {
            st2.insert(x);
            if (st2.size() == 2 || st.find(x) != st.end()) {
                cout << i;
                return ;
            }
        }
    }
    cout << -1;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int t = 1;
    //cin >> t;

    while (t--) {

        solve();

    }

    return 0;
}

全部评论

相关推荐

牛客773130651号:巨佬,简历模板换成上下的,左右的很烦,hr看着不爽。。。科大随便乱杀,建议能保研就保研,不行也得考一下 ,985硕去干算法,比开发强多了。开发许多双非都能搞,学历优势用不上,算法有门槛
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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