Channel Allocation(DFS)
Channel Allocation
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 18 Accepted Submission(s) : 7
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.
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.
#include <iostream>
#include<cstdio>
#include <cstring>
using namespace std;
int kiss[][]={};
bool kisscode[][]={};
int n;
int sgin=;
string s; int strbian()//对相邻关系进行识别
{
if(s.length()==)
return ;
char a;
a=s[];
for(int i=;i<s.length();i++){
kisscode[a-'A'][s[i]-'A']=true;
}
return ;
}
bool dfs(int colersum)
{
bool coler[];
memset(coler,true,sizeof(coler));
if(sgin==n+)
return true;
for(int i=;i<n;i++){
if(kisscode[sgin][i])
coler[kiss[sgin][i]]=false;
}
for(int i=;i<=colersum;i++){
if(coler[i]){//找到相邻位置上没有的颜色
for(int j=;j<=n;j++){//将第sgin个位置进行涂色
kiss[j][sgin]=i;
}
sgin++;
bool a=dfs(colersum);
if(a)
return true;
// sgin--;
// for(int j=0;j<=n;j++){
// kiss[j][sgin]=0;
// }
}
}
return false;
} int main()
{
// freopen("input.txt","r",stdin);
while(cin>>n){
if(n==)
break;
memset(kisscode,false,sizeof(kisscode));
memset(kiss,,sizeof(kiss));
sgin=;
for(int i=;i<n;i++){
cin>>s;
strbian();
}
for(int i=;i<=;i++){
bool a=dfs(i);
if(a){
if(i==){//进行输出,一定注意1种和其他的区别
cout<<i<<" channel needed. "<<endl;
break;
}
else{
cout<<i<<" channels needed. "<<endl;
break;
}
}
}
}
return ;
}
Channel Allocation(DFS)的更多相关文章
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
- POJ-1129 Channel Allocation (DFS)
Description When a radio station is broadcasting over a very large area, repeaters are used to retra ...
- LeetCode Subsets II (DFS)
题意: 给一个集合,有n个可能相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: 看这个就差不多了.LEETCODE SUBSETS (DFS) class Solution { publ ...
- LeetCode Subsets (DFS)
题意: 给一个集合,有n个互不相同的元素,求出所有的子集(包括空集,但是不能重复). 思路: DFS方法:由于集合中的元素是不可能出现相同的,所以不用解决相同的元素而导致重复统计. class Sol ...
- HDU 2553 N皇后问题(dfs)
N皇后问题 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Description 在 ...
- 深搜(DFS)广搜(BFS)详解
图的深搜与广搜 一.介绍: p { margin-bottom: 0.25cm; direction: ltr; line-height: 120%; text-align: justify; orp ...
- 【算法导论】图的深度优先搜索遍历(DFS)
关于图的存储在上一篇文章中已经讲述,在这里不在赘述.下面我们介绍图的深度优先搜索遍历(DFS). 深度优先搜索遍历实在访问了顶点vi后,访问vi的一个邻接点vj:访问vj之后,又访问vj的一个邻接点, ...
- 深度优先搜索(DFS)与广度优先搜索(BFS)的Java实现
1.基础部分 在图中实现最基本的操作之一就是搜索从一个指定顶点可以到达哪些顶点,比如从武汉出发的高铁可以到达哪些城市,一些城市可以直达,一些城市不能直达.现在有一份全国高铁模拟图,要从某个城市(顶点) ...
- 深度优先搜索(DFS)和广度优先搜索(BFS)
深度优先搜索(DFS) 广度优先搜索(BFS) 1.介绍 广度优先搜索(BFS)是图的另一种遍历方式,与DFS相对,是以广度优先进行搜索.简言之就是先访问图的顶点,然后广度优先访问其邻接点,然后再依次 ...
随机推荐
- 《C++反汇编与逆向分析技术揭秘》——函数的工作原理
各种调用方式的考察 示例: cdecl方式是调用者清空堆栈: 如果执行的是fastcall: 借助两个寄存器传递参数: 参数1和2借助局部变量来存储: 返回值 如果返回值是结构体: 返回值存放在eax ...
- excel 导入 与 导出
Excel导入 public ActionResult Excel(HttpPostedFileBase file) { HttpPostedFileBase fi ...
- 详细介绍Java垃圾回收机制
垃圾收集GC(Garbage Collection)是Java语言的核心技术之一,之前我们曾专门探讨过Java 7新增的垃圾回收器G1的新特性,但在JVM的内部运行机制上看,Java的垃圾回收原理与机 ...
- Highcharts属性介绍
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...
- [河南省ACM省赛-第三届] 网络的可靠性 (nyoj 170)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=170 根据题意,需要找到度数为1的结点个数,如下图: #include<iostre ...
- 利用LibreOffice与ImageMagick将网页分享至微信
现在越来越多的内容分享都是在微信上进行了.然而,若想将电脑浏览器中看到的感兴趣的网页分享至微信,则只能以纯文本的方式粘贴超级链接,而不能直接拷贝图文混排的HTML.因此,我想到不妨借助LibreOff ...
- BGP多线单IP技术实现形式以及其他双线对比
自从电信与网通分离之后,北方网通与南方电信网络的互联瓶颈问题一直没有得到很好的解决,这个问题也严重困扰广大的ICP服务商.ICP也只能根据自己网站主流用户群是在南方还是在北方,服务重点是在南方还是北方 ...
- rebase
/BASE (Base Address) https://msdn.microsoft.com/en-us/library/f7f5138s.aspx Need for Rebasing a DLL( ...
- freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建
今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...
- JAVA语法基础(课堂ppt问题总结)
一:运行源代码EnumTest.java,分析运行结果. 代码如下: public class EnumTest { public static void main(String[] args) { ...