Channel Allocation
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 14601   Accepted: 7427

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


题意:给一个地图涂色,最多几种颜色就可以

根据四色定理,迭代加深搜索就行了,最多到四种
//
// main.cpp
// poj2157
//
// Created by Candy on 9/30/16.
// Copyright © 2016 Candy. All rights reserved.
// #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
const int N=;
int n;
char s[N];
struct edge{
int v,ne;
}e[N*N];
int h[N],cnt=;
inline void ins(int u,int v){
cnt++;
e[cnt].v=v;e[cnt].ne=h[u];h[u]=cnt;
}
int col[N],num=,has[N],maxcol,flag;
inline bool check(int u){
for(int i=h[u];i;i=e[i].ne)
if(col[e[i].v]==col[u]) return ;
return ;
}
void dfs(int d){
if(d>n) {flag=;return;}
if(flag) return;
for(int cur=;cur<=maxcol;cur++){
col[d]=cur;
if(check(d)) dfs(d+);
col[d]=;
} }
int main(int argc, const char * argv[]) {
while(scanf("%d",&n)!=EOF&&n){
cnt=;memset(h,,sizeof(h));memset(col,,sizeof(col));
for(int i=;i<=n;i++){
scanf("%s",s+);
int len=strlen(s+);int u=s[]-'A'+;
for(int j=;j<=len;j++){
ins(u,s[j]-'A'+);
}
}
for(maxcol=;maxcol<=;maxcol++){
flag=;
dfs();
if(flag){
if(maxcol==)printf("1 channel needed.\n");
else printf("%d channels needed.\n",maxcol);
break;
}
}
} }

POJ1129Channel Allocation[迭代加深搜索 四色定理]的更多相关文章

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

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

  2. BZOJ1085: [SCOI2005]骑士精神 [迭代加深搜索 IDA*]

    1085: [SCOI2005]骑士精神 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1800  Solved: 984[Submit][Statu ...

  3. 迭代加深搜索 codevs 2541 幂运算

    codevs 2541 幂运算  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题目描述 Description 从m开始,我们只需要6次运算就可以计算出 ...

  4. HDU 1560 DNA sequence (IDA* 迭代加深 搜索)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1560 BFS题解:http://www.cnblogs.com/crazyapple/p/321810 ...

  5. UVA 529 - Addition Chains,迭代加深搜索+剪枝

    Description An addition chain for n is an integer sequence  with the following four properties: a0 = ...

  6. hdu 1560 DNA sequence(迭代加深搜索)

    DNA sequence Time Limit : 15000/5000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  7. 迭代加深搜索 C++解题报告 :[SCOI2005]骑士精神

    题目 此题根据题目可知是迭代加深搜索. 首先应该枚举空格的位置,让空格像一个马一样移动. 但迭代加深搜索之后时间复杂度还是非常的高,根本过不了题. 感觉也想不出什么减枝,于是便要用到了乐观估计函数(O ...

  8. C++解题报告 : 迭代加深搜索之 ZOJ 1937 Addition Chains

    此题不难,主要思路便是IDDFS(迭代加深搜索),关键在于优化. 一个IDDFS的简单介绍,没有了解的同学可以看看: https://www.cnblogs.com/MisakaMKT/article ...

  9. UVA11212-Editing a Book(迭代加深搜索)

    Problem UVA11212-Editing a Book Accept:572  Submit:4428 Time Limit: 10000 mSec  Problem Description ...

随机推荐

  1. CSS3 一、文本阴影text-shadow属性

    文本阴影text-shadow属性特效: 1.右下角阴影,左下角阴影,左上角阴影,右上角阴影 <!DOCTYPE html> <html lang="en"> ...

  2. Request.MapPath和ServerMapPath

    一.路径 / 念 反斜杠,/ 是超文本协议的路径分隔符号,所有的网站在浏览器中显示的路径分隔都是以"/"表示.它一般代表虚拟路径. \ 念 斜杠,在普通程序代码中则以"\ ...

  3. [转]很详细的devexpress应用案例

    很详细的devexpress应用案例,留着以后参考. 注:转载自http://***/zh-CN/App/Feature.aspx?AppId=50021 UPMS(User Permissions ...

  4. 对抽屉效果几大github第三方库的调研

    在公司项目新版本方案选择中,对主导航中要使用的抽屉效果进行了调研.主要原因是旧的项目中所用的库ECS评价不是很好.现对当下比较火的几大热门抽屉效果的第三方库进行了调研.代码全部选自github 如果你 ...

  5. 手动配置 Android SDK

      下载地址与说明http://www.androiddevtools.cn/#sdk-list   手动添加 SDK   这是Android开发所需的sdk,下载并解压后,将解压出的整个文件夹复制或 ...

  6. iOS开发--遇到ARGB/RGBA怎么办

    一.前言 在iOS开发过程中,我们经常会用16进制来表示色值,一般来说我们都是这样表示的:比如#000000表示黑色,#ffffff表示白色,但是如果我们想来个透明度呢? 接下来就让我们来了解一下怎么 ...

  7. eclipse怎样在线安装hibernate tools插件并使用

    不知不觉,小Alan已经将近3个月没有上班了,最近在复习一些知识,随时准备回到代码世界的战场,今天复习到了Hibernate,记录一下一点点小知识,那就是eclipse下hibernate Tools ...

  8. Mysql查询按照某字段指定顺序排序

    在项目当中用到Sphinx的时候,很多人遇到了这样的问题:使用mysql+Sphinx检索出了相关度的ID后,如何按照指定ID在Mysql中进行排序呢?这里是我在项目中的解决方法: 1 SELECT ...

  9. ORACLE中伪表 dual 的用法

     dual是一个虚拟表,用来构成select的语法规则,oracle保证dual里面永远只有一条记录.我们可以用它来做很多事情,如下: 1.查看当前用户,可以在 SQL Plus中执行下面语句 sel ...

  10. 因GIT默认忽略.dll文件导致的Visual Studio项目通过Bamboo编译失败

    背景 由GIT管理的Visual Studio项目,使用Stash管理远端代码库,通过与Stash集成的Bamboo生成项目并发布 现象 Visual Studio项目本地生成成功,用SourceTr ...