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 HTTP实例 使用GET方法和POST方法发送请求

    Android HTTP实例 使用GET方法和POST方法发送请求 Web程序:使用GET和POST方法发送请求 首先利用MyEclispe+Tomcat写好一个Web程序,实现的功能就是提交用户信息 ...

  2. 微信小程序管理后台介绍

    微信小程序的管理后台,每次进入都需要扫码,还是特别不爽,现在微信小程序还没正式发布,很多人都还没看到管理后台,这里抢先发布出来 ------------------------------------ ...

  3. webView 显示一段 html 代码

    1.布局文件 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:and ...

  4. 【代码笔记】iOS-判断有无网络

    一,工程图. 二,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController : UIVi ...

  5. GitHub Top 100 的项目(iOS)

    主要对当前 GitHub 排名前 100 的项目做一个简单的简介, 方便初学者快速了解到当前 Objective-C 在 GitHub 的情况. Android 版本的在此: https://gith ...

  6. Tableau——BI software

    Tableau 8权威指南 (权威的数据可视化实战手册,中国传媒大学教授沈浩.北京大学研究员袁晓如 联袂推荐) 触手可及的大数据分析工具——Tableau案例集 写给专业数据分析师的丛书,无门槛的大数 ...

  7. 修改Mac系统的默认截图保存路径到指定目录

    注:此文仅针对mac系统如果你是mac用户,会发现桌面经常一团糟,桌面到处都是平时的截图(mac系统的截图是command+shift+3 和 command+shift+4 两个快捷命令) 之前一直 ...

  8. go sync.Mutex 设计思想与演化过程 (一)

    go语言在云计算时代将会如日中天,还抱着.NET不放的人将会被淘汰.学习go语言和.NET完全不一样,它有非常简单的runtime 和 类库.最好的办法就是将整个源代码读一遍,这是我见过最简洁的系统类 ...

  9. PL/SQL远程备份和恢复Oracle数据库

    (转自:http://blog.csdn.net/huchunfu/article/details/25165901) 在客户端远程备份的文件保存在数据库所在主机上,不会直接拷贝到客户端.—————— ...

  10. org.apache.jasper.JasperException: Unable to compile class for JSP

    项目启动时报错 : The method getJspApplicationContext(ServletContext) is undefined for the type JspFactory S ...