Channel Allocation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14361   Accepted: 7311

Description

When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully chosen so that nearby repeaters do not interfere with one another. This condition is satisfied if adjacent repeaters use different channels.

Since the radio frequency spectrum is a precious resource, the number of channels required by a given network of repeaters should be minimised. You have to write a program that reads in a description of a repeater network and determines the minimum number of
channels required.

Input

The input consists of a number of maps of repeater networks. Each map begins with a line containing the number of repeaters. This is between 1 and 26, and the repeaters are referred to by consecutive upper-case letters of the alphabet
starting with A. For example, ten repeaters would have the names A,B,C,...,I and J. A network with zero repeaters indicates the end of input.

Following the number of repeaters is a list of adjacency relationships. Each line has the form:

A:BCDH

which indicates that the repeaters B, C, D and H are adjacent to the repeater A. The first line describes those adjacent to repeater A, the second those adjacent to B, and so on for all of the repeaters. If a repeater is not adjacent to any other, its line
has the form

A:

The repeaters are listed in alphabetical order.

Note that the adjacency is a symmetric relationship; if A is adjacent to B, then B is necessarily adjacent to A. Also, since the repeaters lie in a plane, the graph formed by connecting adjacent repeaters does not have any line segments that cross.

Output

For each map (except the final one with no repeaters), print a line containing the minumum number of channels needed so that no adjacent channels interfere. The sample output shows the format of this line. Take care that channels
is in the singular form when only one channel is required.

Sample Input

2
A:
B:
4
A:BC
B:ACD
C:ABD
D:BC
4
A:BCD
B:ACD
C:ABD
D:ABC
0

Sample Output

1 channel needed.
3 channels needed.
4 channels needed.

Source

无向图染色问题。如果缺乏有关染色的知识,可以从这样的角度思考:求解的染色顺序对结果没有影响,这就意味这我们可以用循环来解决这个问题。只需枚举点兵观察与当前点相邻并且已经染色了的点的颜色就可以求出该点的颜色,不需要考虑未染色的邻点。

15859881 ksq2013 1129 Accepted 696K 0MS G++ 956B 2016-08-01 09:52:17
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,mxn,col[27];
bool g[27][27],vis[27];
inline void read()
{
mxn=1;
memset(g,0,sizeof(g));
memset(col,0,sizeof(col));
getchar();
for(int i=1;i<=n;i++){
char ch;
getchar();getchar();
while((ch=getchar())!='\n'){
int u=i,v=ch-'A'+1;
g[u][v]=g[v][u]=1;
}
}
}
inline void solve()
{
col[1]=1;
for(int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
for(int j=1;j<=n;j++)
if(g[i][j])
vis[col[j]]=1;
col[i]=n+1;
for(int k=1;k<=n;k++)
if(!vis[k])
col[i]=min(col[i],k);
mxn=max(mxn,col[i]);
}
}
int main()
{
while(scanf("%d",&n)&&n){
read();
solve();
if(mxn>1)printf("%d channels needed.\n",mxn);
else puts("1 channel needed.");
}
return 0;
}

poj1129 Channel Allocation的更多相关文章

  1. poj1129 Channel Allocation(染色问题)

    题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...

  2. 快速切题 poj1129 Channel Allocation

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12334   Accepted: 63 ...

  3. POJ-1129 Channel Allocation (DFS)

    Description When a radio station is broadcasting over a very large area, repeaters are used to retra ...

  4. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

  5. Channel Allocation

    Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13231 Accepted: 6774 D ...

  6. Channel Allocation (poj 1129 dfs)

    Language: Default Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12 ...

  7. Channel Allocation(DFS)

    Channel Allocation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  8. POJ 1129 Channel Allocation(DFS)

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13173   Accepted: 67 ...

  9. POJ 1129 Channel Allocation DFS 回溯

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 15546   Accepted: 78 ...

随机推荐

  1. Android pull解析xml文件

    本文介绍android中使用pull来解析xml文件 先自己写一个xml文件,存一些天气信息 <?xml version="1.0" encoding="UTF-8 ...

  2. 【代码笔记】iOS-截屏功能

    代码: - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. // ...

  3. Windows 编程中的字符串(2)

    (1)windows写日志系统 void writeDebugEventLog(TCHAR* pszMessage, WORD wType) { //#ifdef _DEBUG HANDLE hEve ...

  4. 使用getopts处理shell中的输入参数

    在编写shell脚本中,经常要处理一些输入参数,在使用过程中发现getopts更加方便,能够很好的处理用户输入的参数和参数值.   getopts用于处理用户输入参数,举例说明使用方法: while ...

  5. 配置mysql远程访问权限,大家可能掉过的那些坑~

    1 作为互联网技术从业人 或者粗暴点说:作为一个程序猿.测试从业者 如果没掉过一些坑,都不好意思说自己混过技术圈     2 今天重点讲:mysql开启远程访问权限的那些坑- 对于mysql开启远程访 ...

  6. js平滑返回顶部代码

    随便找的一个,使用时直接调用gotoTop就行了,至于调速度之类的我没试,有兴趣的自己试试吧 注意:如果你想改变这个函数的名称千万不要忘了要同时改变第37行的那个gotoTop /** * JavaS ...

  7. SQL Tune Report–sqltrpt.sql

    ORACLE 10g提供了一个脚本sqltrpt.sql用来查询最耗费资源的SQL语句,其输出的结果分为两部分: 15 Most expensive SQL in the cursor cache 1 ...

  8. 0001 Oracle数据库安装

    从这个月初开始学习Oracle,因为完全是零起步,就从Oracle的下载安装开始一点一点学起,今天把系统重新做了,就再安装了一遍Oracle11gR2,把安装过程记录一下: 一.安装Oracle数据库 ...

  9. PHP加密3DES报错 Call to undefined function: mcrypt_module_open() 的解决方法

    我也是PHP新手,通过w3cschool了解了一下php基本原理之后就开写了.但仍是菜鸟. 先不管3DES加密的方法对不对,方法都是网上的,在运行的时候报了个错,把小弟整死了.找来找去终于自己摸出了方 ...

  10. MySQL创建数据库和表的Demo

    Demo: 创建数据库的语法 1.基本语法 create database tour character set gbk; use tour; 无主键自增长的 create table EMB_T_E ...