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. [SharePoint] SharePoint 错误集 3

    阅读目录 1. workflow 流程走不下去,报 workflow fails to run 的错误 2. 安装sharepoint prerequisit总是在web server (iis)这步 ...

  2. Atitit.病毒木马的快速扩散机制原理nio 内存映射MappedByteBuffer

    Atitit.病毒木马的快速扩散机制原理nio 内存映射MappedByteBuffer 1. Java NIO(New Input/Output)1 1.1. 变更通知(因为每个事件都需要一个监听者 ...

  3. 高性能JS笔记3——DOM编程

    一.访问与修改DOM DOM和JS 相当于两个岛屿,访问操作的次数越多,要交的过路费越多,对性能产生很大影响. 减少访问DOM的次数,把运算尽量留在JS端操作. 二.innerHTML 对比 DOM ...

  4. Swift获取屏幕快照

    // 获取屏幕快照 private func screenShot() -> UIImage{ let window = UIApplication.shared.keyWindow! UIGr ...

  5. UWP开发中两种网络图片缓存方法

    通常情况下,我们的程序需要从服务器读取图片,但如果需要不止一次读取某一张图片的话,就需要做本地缓存了,这样既为用户省一点流量,又能显得你的APP很快. 假如你已经知道了某一张图片的地址,那么第一件事就 ...

  6. Java 引用

    Java 对象的引用方式有如下四种,这四种方式主要是为了给垃圾回收提供更灵活的操作: 1.强引用,最常见的引用方式,当一个对象被一个或一个以上的引用变量引用时,它处于可达状态,这时不会被垃圾回收器回收 ...

  7. zend studio 使用总结

    1 修改中文字体打开zend studio -> Window -> Preferences -> General -> Apperance -> Colors and ...

  8. HashSet vs TreeSet vs LinkedHashSet

    使用Set集合的主要原因是因为Set集合里面没有重复的元素.Set集合有三个常见的实现类:HashSet,TreeSet,LinkedHashSet.什么时候,选择哪一个使用非常重要.简单的说,如果你 ...

  9. linux pstack命令总结

    pstack命令用来显示进程的栈跟踪. pstack 命令必须由相应进程的属主或root账号运行.可以使用pstack来确定进程挂起的位置.此命令只有一个参数,那就是pid,具体关于pstack的介绍 ...

  10. 如何从SharePoint Content DB中查询List数据

    SharePoint用来维护基础数据非常方便,只需要建立自定义列表,然后使用InfoPath自定义一下维护界面,就可以实现在线的增删改查,开发效率很高.如果维护的数据需要进行审批,还可以加入工作流功能 ...