首页 技术 正文
技术 2022年11月18日
0 收藏 795 点赞 2,142 浏览 2860 个字

Channel Allocation

Time Limit: 1000 MS Memory Limit: 10000 KB

64-bit integer IO format: %I64d , %I64u Java class name: Main

[Submit] [Status] [Discuss]

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.
#include <iostream>
#include <string.h>
#include <stdio.h>using namespace std;
/*int n; ///n个广播站
bool map[35][35]; ///个广播站之间的联系关系
int ans; ///需要多少广播站
int color[35]; ///染色
bool IsFind;*/int n;
bool IsFind;
int ans;
int color[];
bool map[][];
///两个版本定义有什么区别呢??????????????????bool OK(int x,int c) ///判断相邻节点颜色是否相同
{
for(int i=;i<n;i++)
{
if(map[x][i]&&c==color[i]) ///id节点与各个节点比较 x与id节点有连边&&颜色重复了
{
return false;
}
}
return true;
}void DFS(int id,int total) ///当前染色节点编号 总共用的颜色数量
{
if(IsFind)
return ;
if(id>=n)
{
IsFind=true;
return ;
} for(int i=;i<=total;i++)
{
if(OK(id,i))
{
color[id]=i; ///符合条件就上色 之前的颜色
DFS(id+,total); ///继续加点
color[id]=; ///回溯
}
}
if(!IsFind) ///之前的颜色都不符合要求
{
ans++; ///加点
DFS(id,total+); ///加颜色
}
}int main()
{
char str[];
while(scanf("%d",&n)!=EOF)
{ if(n==)
break;
memset(map,false,sizeof(map));
memset(color,,sizeof(color));
for(int i=;i<=n;i++)
{
cin>>str;
int len=strlen(str);
for(int j=;j<=len;j++)
{
map[str[]-'A'][str[j]-'A']=true;;
}
}
IsFind=false;
ans=;
DFS(,);
if(ans==)
printf("1 channel needed.\n");
else
printf("%d channels needed.\n",ans);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860