Channel Allocation
Channel Allocation
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 13231 Accepted: 6774
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
Southern African 2001
看的Discuss说要用四色定理,不懂,所以就是纯粹的暴力,对于每个节点记录它所连得节点,赋给这个节点和它相连的节点没有的颜色并且是最小的
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF =0x3f3f3f3f;
const int Max =120;
typedef pair <int ,int >p;
bool Map[30][30];
int colour[30];
bool vis[30];
int n,m;
int main()
{
char s,c;
char str[30];
int MM;
while(scanf("%d",&n)&&n)
{
memset(Map,false,sizeof(Map));
for(int i=0;i<n;i++)
{
scanf("%c%c%s",&s,&c,str);
for(int j=0;str[j];j++)
{
Map[i][str[j]-'A']=true;
}
}
memset(colour,-1,sizeof(colour));
MM=-1;
for(int i=0;i<n;i++)
{
colour[i]=n+1;
memset(vis,false,sizeof(vis));
for(int j=0;j<n;j++)
{
if(Map[i][j]&&colour[j]!=-1)
{
vis[colour[j]]=true;
}
}
for(int j=1;j<=n;j++)
{
if(!vis[j])
{
colour[i]=j;
break;
}
}
if(MM<colour[i])
{
MM=colour[i];
}
}
if(MM==1)
{
printf("1 channel needed.\n");
}
else
{
cout<<MM<<" channels needed."<<endl;
}
}
return 0;
}
Channel Allocation的更多相关文章
- poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14361 Accepted: 73 ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- poj1129 Channel Allocation(染色问题)
题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...
- Channel Allocation (poj 1129 dfs)
Language: Default Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12 ...
- Channel Allocation(DFS)
Channel Allocation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
- 快速切题 poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12334 Accepted: 63 ...
- POJ 1129 Channel Allocation DFS 回溯
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15546 Accepted: 78 ...
- POJ 1129:Channel Allocation 四色定理+暴力搜索
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13357 Accepted: 68 ...
随机推荐
- Java基础(56):Java---Assertion的试用(华为OJ里的Java题目的用例检测就是用的断言)
一.assertion的意义和用法 J2SE 1.4在语言上提供了一个新特性,就是assertion功能,它是该版本在Java语言方面最大的革新. 从理论上来说,通过 assertion方式可以证明程 ...
- linux下利用nginx部署python网站
首先目标机器需要安装python nginx uwsgi,其次,需要给Nginx写配置文件,大体内容如下,具体内容可见 http://blog.cn2p.com/web-server/nginx-uw ...
- UVA 10891 Game of Sum(DP)
This is a two player game. Initially there are n integer numbers in an array and players A and B get ...
- java使用json将HashMap转化成javabean小例子
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import net.sf.json.JSONOb ...
- 8. 星际争霸之php设计模式--享元模式
题记==============================================================================本php设计模式专辑来源于博客(jymo ...
- [php] PHPExcel插入图片
其它的代码就不贴了,直接上关键代码: $objPHPExcel = new PHPExcel(); $objPHPExcel->setActiveSheetIndex(0); $objActSh ...
- 三、Java基础---------关于继承、构造函数、静态代码块执行顺序示例讲解
在上节博客中曾提到过类的继承,这篇文章主要是介绍类的继承.构造函数以及静态代码块的执行顺序. 首先接着分析在黑马基础测试中的一个关于继承的题目,题目描述如下: 声明类Person,包含2个成员变量:n ...
- Python标准库之核心模块学习记录
内建函数和异常 包括__builtin__模块和exceptions模块 操作系统接口模块 包括提供文件和进程处理功能的os模块,提供平台独立的文件名处理(分拆目录名,文件名,后缀等)的os.path ...
- sql数据库(资料库)的基本操作
1 Character Set与Collation 任何资讯技术在处理资料的时候,如果只是单纯的数值和运算,那就不会有太复杂的问题:如果处理的资料是文字的话,就会面临世界上各种不同语言的问题.以资料库 ...
- 数据库订正脚本性能优化两则:去除不必要的查询和批量插入SQL
最近在做多数据库合并的脚本, 要将多个分数据库的表数据合并到一个主数据库中. 以下是我在编写数据订正脚本时犯过的错误, 记录以为鉴. 不必要的查询 请看以下语句: regiondb = db.Houy ...