poj1129 Channel Allocation
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 14361 | Accepted: 7311 |
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
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
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
无向图染色问题。如果缺乏有关染色的知识,可以从这样的角度思考:求解的染色顺序对结果没有影响,这就意味这我们可以用循环来解决这个问题。只需枚举点兵观察与当前点相邻并且已经染色了的点的颜色就可以求出该点的颜色,不需要考虑未染色的邻点。
| 15859881 | ksq2013 | 1129 | Accepted | 696K | 0MS | G++ | 956B | 2016-08-01 09:52:17 |
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
int n,mxn,col[27];
bool g[27][27],vis[27];
inline void read()
{
mxn=1;
memset(g,0,sizeof(g));
memset(col,0,sizeof(col));
getchar();
for(int i=1;i<=n;i++){
char ch;
getchar();getchar();
while((ch=getchar())!='\n'){
int u=i,v=ch-'A'+1;
g[u][v]=g[v][u]=1;
}
}
}
inline void solve()
{
col[1]=1;
for(int i=1;i<=n;i++){
memset(vis,0,sizeof(vis));
for(int j=1;j<=n;j++)
if(g[i][j])
vis[col[j]]=1;
col[i]=n+1;
for(int k=1;k<=n;k++)
if(!vis[k])
col[i]=min(col[i],k);
mxn=max(mxn,col[i]);
}
}
int main()
{
while(scanf("%d",&n)&&n){
read();
solve();
if(mxn>1)printf("%d channels needed.\n",mxn);
else puts("1 channel needed.");
}
return 0;
}
poj1129 Channel Allocation的更多相关文章
- poj1129 Channel Allocation(染色问题)
题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...
- 快速切题 poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12334 Accepted: 63 ...
- POJ-1129 Channel Allocation (DFS)
Description When a radio station is broadcasting over a very large area, repeaters are used to retra ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
- Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13231 Accepted: 6774 D ...
- Channel Allocation (poj 1129 dfs)
Language: Default Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12 ...
- Channel Allocation(DFS)
Channel Allocation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
- POJ 1129 Channel Allocation DFS 回溯
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 15546 Accepted: 78 ...
随机推荐
- SharePoint 2013 为站点配置基于主机标头的双域名
SharePoint的应用中,经常需要配置双域名,为不同的认证方式提供访问入口,下面简单介绍下,如何以主机标头的方式为SharePoint配置双域名: 配置基于主机标头的双域名 1.原本可以访问的测试 ...
- android listview多视图嵌套多视图
笔记,listview视图总结 public class HomeEduMoreAdapter extends BaseAdapter { private final String TAG = &qu ...
- Android客户端与服务器
就是普通的服务器端编程,还不用写界面,其实还比服务器编程简单一些.跟J2EE一样的服务器,你android这一方面只要用json或者gson直接拿数据,后台的话用tomcat接受请求操作数据,功能不复 ...
- 深入.net(多态一)
代码优化技术: 当您在 编写一个类时,如果您发现你需要编写的“属性”和“方法”曾经在已有的类中实现,则,您可以将其共用的“属性”和“方法”剪切到一个新的“类”中,然后,让两个类共同继承这个“新类”.( ...
- 【代码笔记】iOS-后台运行,可以选择在前台或后台或前后台
一,工程图. 二,代码. AppDelegate.h AppDelegate.m RootViewController.h #import <UIKit/UIKit.h> @interfa ...
- 【代码笔记】iOS-侧滑效果
一,效果图. 二,工程图. 三,代码. AppDelegate.h #import <UIKit/UIKit.h> //加入头文件 #import "PPRevealSideVi ...
- Spring的IOC逐层深入——依赖注入的两种实现类型
构造器注入 构造器注入,即通过构造函数完成依赖关系的设定.我们看一下spring的配置文件: <?xml version="1.0" encoding="UTF-8 ...
- 【AdaBoost算法】弱分类器训练过程
一.加载数据(正样本.负样本特征) def loadSimpData(): #样本特征 datMat = matrix([[ 1. , 2.1, 0.3], [ 2. , 1.1, 0.4], [ 1 ...
- SQL Server(一)——数据库基础知识
SQL:Structured Quety Language SQL SERVER是一个以客户/服务器(c/s)模式访问.使用Transact-SQL语言的关系型数据库管理子系统(RDBMS) DBMS ...
- SQL中CHARINDEX()/INSTR()函数和SUBSTRING()/SUBSTR()函数
一.SQLServer中的CHARINDEX() 和ORACLE中的INSTR()函数 1.INSTR(C1,C2[,I[,J]]) [功能]在一个字符串中搜索指定的字符,返回发现指定的字符的位置; ...