poj 1129 搜索
Channel Allocation
Time Limit: 1000 MS Memory Limit: 10000 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
Description
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
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
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 搜索的更多相关文章
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- catch that cow POJ 3278 搜索
catch that cow POJ 3278 搜索 题意 原题链接 john想要抓到那只牛,John和牛的位置在数轴上表示为n和k,john有三种移动方式:1. 向前移动一个单位,2. 向后移动一个 ...
- POJ 1129:Channel Allocation 四色定理+暴力搜索
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13357 Accepted: 68 ...
- poj 1129 Channel Allocation ( dfs )
题目:http://poj.org/problem?id=1129 题意:求最小m,使平面图能染成m色,相邻两块不同色由四色定理可知顶点最多需要4种颜色即可.我们于是从1开始试到3即可. #inclu ...
- POJ 1129 Channel Allocation 四色定理dfs
题目: http://poj.org/problem?id=1129 开始没读懂题,看discuss的做法,都是循环枚举的,很麻烦.然后我就决定dfs,调试了半天终于0ms A了. #include ...
- poj 1129 Channel Allocation
http://poj.org/problem?id=1129 import java.util.*; import java.math.*; public class Main { public st ...
- poj 1129(dfs+图的四色定理)
题目链接:http://poj.org/problem?id=1129 思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同.而最多又只有26个点,因此直接dfs即可. #inc ...
- [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解
目录 POJ 1426 POJ 1321 POJ 2718 POJ 3414 POJ 1416 POJ 2362 POJ 3126 POJ 3009 个人整了一些搜索的简单题目,大家可以clone来练 ...
- poj 2251 搜索
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13923 Accepted: 5424 D ...
随机推荐
- 离线在MVC4中的使用
最近在项目中用到了离线功能,自己感觉挺高端的,但是遇到了一些问题. 现在工作告一小段落,就把这次离线工作中遇到的关键技术点和难题记录下来. 什么是离线,什么时候需要离线 离线:Offline,不联网也 ...
- 20172325 2018-2019-1 《Java程序设计》第二周学习总结
20172325 2018-2019-1 <Java程序设计>第二周学习总结 教材学习内容总结 3.1集合 集合是一种聚集.组织了其他对象的对象.集合可以分为两大类:线性集合和非线性集合. ...
- Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用
Spring 注解驱动(二)Servlet 3.0 注解驱动在 Spring MVC 中的应用 Spring 系列目录(https://www.cnblogs.com/binarylei/p/1019 ...
- unwind
unwind:可以将一个列表展开为一个行的序列1.列表 unwind[1,2,3]as x return x2.创建唯一列表with[1,2,3,3]as coll unwind coll as x ...
- mysql bigint ,int , smallint,tinyint 的范围
bigint 8字节 64位 int 4字节 32位 smallint 2字节 16位 tinyint 1字节8位 .. 范围 -128 到 127 , 如果是无符号 ,则返回 位 0-255 ...
- 博客写作的Checklist
Checklist 1.不要发明术语. 2.不要使用指代不清的代词.如:我,他. 3.不要使用错误的承前省. 4.不要使用口语. 5.给出结论之前,先交代背景. 6.站立会议报告中应有燃尽图. 7.燃 ...
- 使用EventLog Analyzer监控、管理及分析日志
- 2019.01.26 codeforces 528D. Fuzzy Search(fft)
传送门 fftfftfft好题. 题意简述:给两个字符串s,ts,ts,t,问ttt在sss中出现了几次,字符串只由A,T,C,GA,T,C,GA,T,C,G构成. 两个字符匹配的定义: 当si−k, ...
- 2018.12.19 codeforces 1092F. Tree with Maximum Cost(换根dp)
传送门 sbsbsb树形dpdpdp题. 题意简述:给出一棵边权为1的树,允许选任意一个点vvv为根,求∑i=1ndist(i,v)∗ai\sum_{i=1}^ndist(i,v)*a_i∑i=1n ...
- TCP/IP协议(2):各层网络设备
一.中继器(Repeater) 中继器工作在OSI的一层物理层,我们知道,超5类线的传输距离最大为100米,超过这个距离信号就会衰减,中继器就是为了防止信号变差,将网络信号进行再生和重定时. 二.集线 ...