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

  1. 2
  2. A:
  3. B:
  4. 4
  5. A:BC
  6. B:ACD
  7. C:ABD
  8. D:BC
  9. 4
  10. A:BCD
  11. B:ACD
  12. C:ABD
  13. D:ABC
  14. 0

Sample Output

  1. 1 channel needed.
  2. 3 channels needed.
  3. 4 channels needed.
  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4.  
  5. using namespace std;
  6. /*int n; ///n个广播站
  7. bool map[35][35]; ///个广播站之间的联系关系
  8. int ans; ///需要多少广播站
  9. int color[35]; ///染色
  10. bool IsFind;*/
  11.  
  12. int n;
  13. bool IsFind;
  14. int ans;
  15. int color[];
  16. bool map[][];
  17. ///两个版本定义有什么区别呢??????????????????
  18.  
  19. bool OK(int x,int c) ///判断相邻节点颜色是否相同
  20. {
  21. for(int i=;i<n;i++)
  22. {
  23. if(map[x][i]&&c==color[i]) ///id节点与各个节点比较 x与id节点有连边&&颜色重复了
  24. {
  25. return false;
  26. }
  27. }
  28. return true;
  29. }
  30.  
  31. void DFS(int id,int total) ///当前染色节点编号 总共用的颜色数量
  32. {
  33. if(IsFind)
  34. return ;
  35. if(id>=n)
  36. {
  37. IsFind=true;
  38. return ;
  39. }
  40.  
  41. for(int i=;i<=total;i++)
  42. {
  43. if(OK(id,i))
  44. {
  45. color[id]=i; ///符合条件就上色 之前的颜色
  46. DFS(id+,total); ///继续加点
  47. color[id]=; ///回溯
  48. }
  49. }
  50. if(!IsFind) ///之前的颜色都不符合要求
  51. {
  52. ans++; ///加点
  53. DFS(id,total+); ///加颜色
  54. }
  55. }
  56.  
  57. int main()
  58. {
  59. char str[];
  60. while(scanf("%d",&n)!=EOF)
  61. {
  62.  
  63. if(n==)
  64. break;
  65. memset(map,false,sizeof(map));
  66. memset(color,,sizeof(color));
  67. for(int i=;i<=n;i++)
  68. {
  69. cin>>str;
  70. int len=strlen(str);
  71. for(int j=;j<=len;j++)
  72. {
  73. map[str[]-'A'][str[j]-'A']=true;;
  74. }
  75. }
  76. IsFind=false;
  77. ans=;
  78. DFS(,);
  79. if(ans==)
  80. printf("1 channel needed.\n");
  81. else
  82. printf("%d channels needed.\n",ans);
  83. }
  84. return ;
  85. }

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 四色定理+暴力搜索

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

  4. poj 1129 Channel Allocation ( dfs )

    题目: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(dfs+图的四色定理)

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

  8. [Vjudge][POJ][Tony100K]搜索基础练习 - 全题解

    目录 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. node.js 进程崩溃处理

    process.on('uncaughtException', (err) => { console.error('有错误'); });

  2. 标准IO缓冲机制

    参考资料: https://q16964777.iteye.com/blog/2228244 知道缓冲有几种模式:无缓冲.行缓冲.全缓冲.通过判断FILTE中的 _flags 的判断可以知道究竟是那种 ...

  3. centOS 6.5下升级mysql,从5.1升级到5.6

    转载:https://www.cnblogs.com/vickygu2007/p/5066409.html #mysqldump -uroot -p --all-databases > data ...

  4. tensorflow下识别手写数字基于MLP网络

    # coding: utf-8 # In[1]: import tensorflow as tf import tensorflow.examples.tutorials.mnist.input_da ...

  5. SQL语句备份和还原数据库

    1,使用SQL最简单备份,还原数据库 1 /* 备份 */ 2 backup database Test to disk='D:/Test.bak' 3 /* 还原 */ 4 restore data ...

  6. 2019.01.22 bzoj3875: [Ahoi2014&Jsoi2014]骑士游戏(spfa+dp)

    传送门 题意简述:nnn个怪物,对于编号为iii的怪物可以选择用aia_iai​代价将其分裂成另外的bib_ibi​个怪物或者用cic_ici​代价直接消灭它,现在问消灭编号为1的怪物用的最小代价. ...

  7. 查阅Springboot官方文档方式----------------Springboot2.0.2最新稳定版

    1.登录官方网址: https://spring.io/ 如图所示: 2.选择PROJECTS,就可以看到spring所有的相关项目了. 点开后:其中就包括了Spingboot 3.版本选择,红圈部分 ...

  8. Windows 下 Quartus 检测不到 USB-Blaster 终极解决办法

    转自https://blog.csdn.net/acang301/article/details/50471067?locationNum=12 一.Windows无法正常驱动USB-Blaster ...

  9. 行转列group_concat()函数妙用

    测试环境准备: mysql> create table test01(name varchar(20),address varchar(20)); Query OK, 0 rows affect ...

  10. 解决FileZilla Server因路径错误导致无法启动问题详细图文教程

    问题背景 我作为一个配置无数服务器环境的人,对服务器的配置也算有所了解,不管是在linux平台还是win平台都比较熟悉,但这次帮一个朋友配置win2003服务器的时候却遇到了一个问题:前面配置IIS和 ...