zoukankan      html  css  js  c++  java
  • Codeforces Round #562 (Div. 2) B. Pairs

    链接:https://codeforces.com/contest/1169/problem/B

    题意:

    Toad Ivan has mm pairs of integers, each integer is between 11 and nn, inclusive. The pairs are (a1,b1),(a2,b2),,(am,bm)(a1,b1),(a2,b2),…,(am,bm).

    He asks you to check if there exist two integers xx and yy (1x<yn1≤x<y≤n) such that in each given pair at least one integer is equal to xx or yy.

    思路:

    单独考虑两个完全不相同的对,例如(1,2)-(3,4), 出现这种对时,x和y只能再这两对中取,所以,用vector记录率先出现的一个队,再找没有出现过的队,如果找不到也无所谓,说明一个队里的已经覆盖了全部。

    再对这最多四个值进行枚举对,挨个查找。

    不过别人思路好像跟我不大一样

    代码:

    #include <bits/stdc++.h>
    
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 3e5 + 10;
    const int MOD = 1e9 + 7;
    pair<int, int> node[MAXN];
    int Dis[MAXN];
    int n, m, k, t;
    int p, q, u, v;
    int x, y, z, w;
    
    bool Serch(int a, int b)
    {
        for (int i = 1;i <= m;i++)
        {
            if (node[i].first != a && node[i].first != b && node[i].second != a && node[i].second != b)
                return false;
        }
        return true;
    }
    
    int main()
    {
        cin >> n >> m;
        vector<int> ser;
        bool flag = true;
        for (int i = 1;i <= m;i++)
        {
            cin >> node[i].first >> node[i].second;
            /*
            Dis[node[i].first]++;
            if ((Dis[node[i].first] == 1&& flag))
            {
                ser.push_back(node[i].first);
                if (ser.size() == 4)
                    flag = false;
            }
            Dis[node[i].second]++;
            if ((Dis[node[i].second] == 1&& flag))
            {
                ser.push_back(node[i].second);
                if (ser.size() == 4)
                    flag = false;
            }
            */
            if (ser.size() < 4)
            {
                bool f = true;
                for (int j = 0; j < ser.size(); j++)
                    if (node[i].first == ser[j])
                        f = false;
                for (int j = 0; j < ser.size(); j++)
                    if (node[i].second == ser[j])
                        f = false;
                if (f)
                    ser.push_back(node[i].first), ser.push_back(node[i].second);
            }
        }
        flag = false;
    //    cout << Serch(2, 4) << endl;
    //    for (auto x:ser)
    //        cout << x << ' ' ;
    //    cout << endl;
        for (int i = 0;i < ser.size();i++)
            for (int j = i+1;j < ser.size();j++)
                if (Serch(ser[i], ser[j]))
                    flag = true;
        if (flag)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    
    
        return 0;
    }
    

      

  • 相关阅读:
    Miracast
    linux软中断与硬中断实现原理概述
    入门视频采集与处理(BT656简介)
    emms指令在MMX指令中的作用
    linux进程的地址空间,核心栈,用户栈,内核线程
    linux 线程的内核栈是独立的还是共享父进程的?
    进程内核栈、用户栈及 Linux 进程栈和线程栈的区别
    Gson JsonParser的使用
    封装JDBC事务操作,执行存储过程测试
    Oracle 存储过程,临时表,动态SQL测试
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10930203.html
Copyright © 2011-2022 走看看