• CCCC 排座位 图着色问题


    1排座位:https://www.patest.cn/contests/gplt/L2-010

    2图着色问题 https://www.patest.cn/contests/gplt/L2-023

    建图XJB暴力的题目

    1.

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <math.h>
    #include <string.h>
    #include <string>
    #include <map>
    #include<stack>
    #include<set>
    #include<string.h>
    #define pb push_back
    #define _for(i, a, b) for (int i = (a); i<(b); ++i)
    #define _rep(i, a, b) for (int i = (a); i <= (b); ++i)
    
    using namespace std;
    const  int N = 100 + 5;
    //double num[N], price[N], ave[N];
    int a[N][N];
    
    
    
    int main() {
        int n, m, k;
        cin >> n >> m >> k;
        memset(a, 0, sizeof(a));
        _for(i, 0, m) {
            int x, y, z;
            cin >> x >> y >> z;
            a[x][y] = a[y][x] = z;
    }
        _for(i, 0, k) {
            int x, y;
            cin >> x >> y;
            if (a[x][y] == 1) { cout << "No problem" << endl; continue; }
            if(a[x][y]==0) { cout << "OK" << endl; continue; }
            int ok = 1;
            if (a[x][y] == -1) {
                _rep(q,1,n)
                    {
                    if (a[x][q] && a[y][q]) { cout << "OK but..." << endl; ok = 0; break; }
                }
                if (ok)cout << "No way" << endl;
            }
        }
        system("pause");
    }

    2图着色:

    #include<iostream>
    #include<algorithm>
    #include<stdio.h>
    #include<string>
    #include<map>
    #include<vector>
    #define _for(i, a, b) for (int i = (a); i<(b); ++i)
    using namespace std;
    typedef long long ll;
    const int N = 500 + 5;
    vector<int> E[N];
    int p[N];
    map<int, int> cnt;
    int main() {
        int v, e, k;
        cin >> v >> e >> k;
        _for(i, 0, e) {
            int x, y;
            cin >> x >> y;
            E[x].push_back(y);
            E[y].push_back(x);
        }
        int n;
        cin >> n;
        while (n--) {
            cnt.clear();
            _for(i, 0, v) {
                cin >> p[i + 1];
                cnt[p[i + 1]]++;
                
            }int ok = 1;
            if (cnt.size() != k)ok=0;
            
            _for(i, 0, v) {
                for (int j = 0; j < E[i+1].size(); j++) {
                    int now = E[i+1][j];
                    if (p[i+1] == p[now]) {
                        ok = 0; break;
                    }
                }
                if (ok == 0)break;
    
            }
            cout << (ok == 1 ? "Yes" : "No") << endl;
        }
        
    }
    成功的路并不拥挤,因为大部分人都在颓(笑)
  • 相关阅读:
    codechef Graph on a Table
    CF1063F. String Journey
    BZOJ1547: 周末晚会
    maxsigma
    LOJ#2351. 「JOI 2018 Final」毒蛇越狱
    BZOJ3632: 外太空旅行
    图论:tarjan相关算法复习
    Codeforces 321E. Ciel and Gondolas(凸优化+决策单调性)
    5031. 【NOI2017模拟3.27】B (k次狄利克雷卷积)
    CSAcademy Round 10 Yury's Tree(有根树点分树或kruskal重构树)
  • 原文地址:https://www.cnblogs.com/SuuT/p/8669586.html
Copyright © 2020-2023  润新知