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;
    }
    
}
成功的路并不拥挤,因为大部分人都在颓(笑)
原文地址:https://www.cnblogs.com/SuuT/p/8669586.html