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的更多相关文章

  1. poj1129 Channel Allocation

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

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

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

  3. poj1129 Channel Allocation(染色问题)

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

  4. Channel Allocation (poj 1129 dfs)

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

  5. Channel Allocation(DFS)

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

  6. POJ 1129 Channel Allocation(DFS)

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

  7. 快速切题 poj1129 Channel Allocation

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

  8. POJ 1129 Channel Allocation DFS 回溯

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

  9. POJ 1129:Channel Allocation 四色定理+暴力搜索

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13357   Accepted: 68 ...

随机推荐

  1. Java基础之处理事件——实现低级事件监听器(Sketcher 2 implementing a low-level listener)

    控制台程序. 定义事件监听器的类必须实现监听器接口.所有的事件监听器接口都扩展了java.util.EventListener接口.这个接口没有声明任何方法,仅仅用于表示监听器对象.使用EventLi ...

  2. mongodb查询文档

    说到查询,我们一般就想起了关系型数据库的查询了,比如:order by(排序).limit(分页).范围查询(大于某个值,小于某个值..,in查询,on查询,like查询等待很多),同样mongodb ...

  3. DB2数据库管理最佳实践(1)

    1.DB2 9的新特性 1)DB2 9.1:主要是增加了原生XML,表分区和表压缩功能.从构架上,总的进程模型和内存构架看,都和8没啥区别. DB2 中的 pureXML 支持为管理 XML 数据提供 ...

  4. 分布式领域CAP理论

    分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...

  5. Smarty模板

    Smarty模板 是做什么用的?? 是将前端的显示和后台的逻辑进行分离,就相当于把前台显示的页面和后台要实现的某些功能的逻辑给分离出来了,分离在两个文件里,也就是说,前端只负责显示,后端只负责逻辑操作 ...

  6. [转]Eclipse Java注释模板设置详解

    原文链接:http://blog.csdn.net/ahhsxy/archive/2009/09/11/4542682.aspx 设置注释模板的入口: Window->Preference-&g ...

  7. Android 利用Service BroadcastReceiver实现小例子

    Activity: package com.example.test; import android.app.Activity; import android.content.Context; imp ...

  8. [ubuntu] Can not run OpenProj on Ubuntu

    Download openproj from http://sourceforge.net/projects/openproj/ Yes, you can only download the rpm ...

  9. 《OpenGL着色语言》理解点记录二

    别人提到“OpenGL的处理管线”时,意味着什么? 准确的讲,应该是“OpenGL图形处理管线”,“管线”带有特定的顺序,在OpenGL中就是Graphics Processing Pipeline. ...

  10. 蒙地卡罗法求 PI

    问题: 蒙地卡罗为摩洛哥王国之首都,该国位于法国与义大利国境,以赌博闻名.蒙地卡罗的基本原理为以乱数配合面积公式来进行解题,这种以机率来解题的方式带有赌博的意味,虽然在精确度上有所疑虑,但其解题的思考 ...