POJ 1129
发布日期:2021-06-30 15:31:16 浏览次数:2 分类:技术文章

本文共 3169 字,大约阅读时间需要 10 分钟。

Channel Allocation

Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 17741   Accepted: 8983

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

2A:B:4A:BCB:ACDC:ABDD:BC4A:BCDB:ACDC:ABDD:ABC0

Sample Output

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

Source

大致题意:

      当一个广播电台在一个非常大的地区,广播站会用中继器来转播信号以使得每一个接收器都能接收到一个强烈的信号。然而,每个中继器必须慎重选择使用,使相邻的中继器不互相干扰。

     如果相邻的中继器使用不同的频道,那么就不会相互干扰。

     由于无线电频道是有限的,一个给定的网络所需的中继频道数目应减至最低。

     编写一个程序,读取一个中继网络,然后求出需要的最低的不同频道数。

解题思路:

   他输入的是中继网络,A:BC意思是A与B与C相邻,然后要给每个结点之间分配频道,使相邻结点频道不会受到干扰。

   我们可以通过输入知道,总共的节点数(即中继器数量),而相邻没有方向区分

   因此得到一个无向图。

   要想使相邻中继器之间不会干扰,那么其使用的频道就不能一致。

   那么就相当于一个图的涂色问题。

  一个有N个节点的无向图,要求对每个节点进行染色,使得相邻两个节点颜色都不同,问最少需要多少种颜色

代码:

#include 
#include
using namespace std;int n;int mapp[26][26];//记录相邻 char str[26];//记录每行输入int color[26];//记录每个结点对应的颜色编号。 void dfs(int d){ if(d==n) return; int cont=1;//终止涂色的变量 int i,j; for(i=1;cont;i++)//在顶点d处,从颜色1开始涂起,颜色编号以i表示 { int flag=1; for(j=0;j
>n&&n>=1) { //每次新开始时要清空原来数据 memset(mapp,0,sizeof(mapp)); memset(color,0,sizeof(color)); //输入n行数据 for(int i=0;i
>str; int a=str[0]-'A'; //将相邻信息统计在map中 for(int j=2;j
1) cout<
<<" channels needed."<

 

转载地址:https://joycez.blog.csdn.net/article/details/83476387 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:POJ 1837
下一篇:POJ 1028

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月18日 10时08分46秒