zoukankan      html  css  js  c++  java
  • POJ

    链接:

    https://vjudge.net/problem/POJ-1129#author=SWUN2018

    题意:

    用大写字母表示一个广播电台,用数字代表广播电台的无线频谱,相邻两个电台之间如果运用同样的无线频谱就会互相干扰,所以我们不会让两个相邻电台之间使用同样的无线频谱.
    现在问你最少使用几种无线频谱使得这些连接的广播电台之间能够正常运作?

    思路:

    每个点染色,保证相邻的两个点颜色不同

    代码:

    //#include<bits/stdc++.h>
    #include<iostream>
    #include<string>
    #include<cstdio>
    #include<vector>
    #include<string.h>
    #include<cstring>
    #include<set>
    #include<queue>
    #include<algorithm>
    #include<math.h>
    #include<stdio.h>
    #include<map>
    #include<stack>
    #include<list>
    #define INF 0x3f3f3f3f
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const int MOD = 20071027;
    const int MAXN = 1010;
    const double eps = 1e-3;
    int Next[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
    
    int n, m;
    vector<int> G[30];
    int color[30], vis[30];
    char s[50];
    
    int solve()
    {
        memset(color, -1, sizeof(color));
        for (int i = 0;i < n;i++)
        {
            memset(vis, 0, sizeof(vis));
            for (int j = 0;j < (int)G[i].size();j++) if (color[G[i][j]] != -1)
                vis[color[G[i][j]]] = 1;
            for (int c = 1;c <= i+1;c++) if (!vis[c])
            {
                color[i] = c;
                break;
            }
        }
        int ans = 0;
        for (int i = 0;i < n;i++) ans = max(ans, color[i]);
        return ans;
    }
    
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0), cout.tie(0);
        while(~scanf("%d", &n) && n)
        {
            for (int i = 1;i <= n;i++) G[i].clear();
            for (int i = 1;i <= n;i++)
            {
                scanf("%s", s);
                int len = strlen(s);
                for (int j = 2;j < len;j++)
                    G[s[0]-'A'].push_back(s[j]-'A');
            }
            int ans = solve();
            if (ans > 1)
                printf("%d channels needed.
    ", ans);
            else
                printf("%d channel needed.
    ", ans);
        }
    
        return 0;
    }
    
  • 相关阅读:
    WF4.0 基础 InvokeMethod 调用方法
    MySQL数据库表名、列名、别名区分大小写的问题
    客户端调用Web服务
    something about Socket
    C#参数传递
    学习内容
    About HttpContext
    Best Sequence [POJ1699] TSPDP
    优先队列
    Watermelon Full of Water [ZOJ 4778]
  • 原文地址:https://www.cnblogs.com/YDDDD/p/12245851.html
Copyright © 2011-2022 走看看