poj 1129 搜索

时间:2023-02-22 22:34:58

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 ;
}

poj 1129 搜索的更多相关文章

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

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

  2. catch that cow POJ 3278 搜索

    catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...

  3. POJ 1129:Channel Allocation 四色定理&plus;暴力搜索

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

  4. poj 1129 Channel Allocation &lpar; dfs &rpar;

    题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...

  5. POJ 1129 Channel Allocation 四色定理dfs

    题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...

  6. poj 1129 Channel Allocation

    http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...

  7. poj 1129&lpar;dfs&plus;图的四色定理&rpar;

    题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #inc ...

  8. &lbrack;Vjudge&rsqb;&lbrack;POJ&rsqb;&lbrack;Tony100K&rsqb;搜索基础练习 - 全题解

    目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...

  9. poj 2251 搜索

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13923   Accepted: 5424 D ...

随机推荐

  1. PHP基础结业感想与总结!

    之前来传智是我认真调查和思考后得出的结论,我做程序员的第一目标是赚钱和学习技术,有一句话"艺多不压身".相信班上所有人的目标都是,这一点都不会庸俗,但是各个人的目的就未必一样了.我 ...

  2. A trip through the Graphics Pipeline 2011&lowbar;06&lowbar;&lpar;Triangle&rpar; rasterization and setup

    Welcome back. This time we’re actually gonna see triangles being rasterized – finally! But before we ...

  3. &lbrack;PaPaPa&rsqb;&lbrack;需求说明书&rsqb;&lbrack;V2&period;0&rsqb;

    前   言 大家好,我是“今晚打老虎”. 什么? 你问我为什么这次亮字号了? 还不是因为哥太出名了,即使我不亮你们也知道是我写的了. 自从发布了V1.0版本之后.群里又进来好多人.30K大大分发的任务 ...

  4. Using CSV-Format Log Output

    Including csvlog in the log_destination list provides a convenient way to import log files into a da ...

  5. Java&lowbar;数组

    一.java数组 1.数组定义:数组就是形象于一个容器(容器即可理解为:装东西的容器) 2.数组特征:数据是连续的,分配大小固定,数组中数据类型完全一致 创建规则:int[] arr = new in ...

  6. offset&lpar;&rpar; position&lpar;&rpar; scrollTop&lpar;&rpar; scrollLeft&lpar;&rpar;

    (1)offset:获取当前元素相对于文档的高度.只对可见元素有效. 不管该元素如何定位,也不管其父元素如何定位,都是获取的该元素相对于当前视口的偏移 (2) position:获取元素相对于最近的一 ...

  7. Nothing

    破烂的文具盒里,一张十年的纸条子和一袋存了十年的德芙巧克力 浅绿色的纸条子上写是当时你给我抄的作业题目,蓝色清秀的字体 但是十年后,你却已嫁他人 将身后的风雪.夕阳,空气埋葬.窑藏,待非常多年以后酿成 ...

  8. 从无到有开发连麦直播技术&lt&semi;转&gt&semi;

    转贴地址:http://blog.csdn.net/heisedelangzi/article/details/52400333 从无到有开发连麦直播技术点整理-AnyRTC 直播关键字 采集.前处理 ...

  9. 走近webpack(4)--css相关拓展

    我们前面已经学了很多webpack基本的处理情况,一句话总结就是,一个优秀的webpack项目,主要的核心用法就是整合loader和plugin去处理你想要的任何需求. 下面,咱们一起来学学如何用we ...

  10. 【收藏】UICrawler

    基于 Appium 的 App UI 遍历 & Monkey 工具 (支持操作步骤回放) UICrawler https://github.com/lgxqf/UICrawler 基于Appi ...