快速切题 poj1129 Channel Allocation
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 12334 | Accepted: 6307 |
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
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
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. 实际用时:21min
原因:....心理准备
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int maxn=50;
int n;
vector <int > G[maxn];
int color[maxn];
int cnt;
bool dfs(int s,int c){
color[s]=c;
for(int i=0;i<G[s].size();i++){
int to=G[s][i];
if(color[to]==c){color[s]=-1;return false;}
if(color[to]==-1){
for(int i=0;i<=cnt;i++){
if(i==cnt)cnt++;
if(i!=c&&dfs(to,i))break;
}
}
}
return true;
}
char buff[50];
int main(){
while(scanf("%d",&n)==1&&n){
gets(buff);
for(int i=0;i<n;i++){
gets(buff);
G[i].clear();
for(int j=2;buff[j];j++){
G[i].push_back(buff[j]-'A');
}
}
memset(color,-1,sizeof(color));
cnt=1;
for(int i=0;i<n;i++)if(color[i]==-1)dfs(i,0);
if(cnt==1)printf("1 channel needed.\n");
else printf("%d channels needed.\n",cnt);
}
return 0;
}
快速切题 poj1129 Channel Allocation的更多相关文章
- poj1129 Channel Allocation(染色问题)
题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...
- poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14361 Accepted: 73 ...
- 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 ...
随机推荐
- 【转】各种消息下wParam及lParam值的含义
转载自:http://bbs.fishc.com/forum.php?mod=viewthread&tid=52668#lastpost 01.WM_PAINT消息 LOWORD(lParam ...
- 【建表】ElasticSearch建表命令
使用google插件Postman 发送方式为PUT,url地址: 192.168.2.11:9200/IndexName 文本raw,数据为json格式 { "settings" ...
- spring boot 多数据源分布式事务处理
有参考文章 ,但是自己没有测试.
- java画流程图【思路】
java计算整数输入 <样例 画的第一张流程图 把脑子里的东西能清晰的表现出来 学编程必备
- CVS导出&&自定义Attribute的使用
1.cvs导出:List转为byte[] /// <summary> /// CvsExport帮助类 /// </summary> public static class C ...
- fusion--RNAseq
融合基因(Fusion gene)是指两个基因的全部或一部分的序列相互融合为一个新的基因的过程.其有可能是染色体易位.中间缺失或染色体倒置所致的结果. 异常的融合基因可以引起恶性血液疾病以及肿瘤.例如 ...
- 【Python】【环境搭建】
[环境配置] Windows : http://blog.csdn.net/zhunianguo/article/details/53524792 [Pycharm] pyCharm最新2018激活码 ...
- 如何上传本地文件到github又如何删除自己的github仓库
首先自己在https://github.com/网站要注册一个账户 自己上传工程到jithub,没有付费的用户只能选用public,意味着你的项目在全网是可以被看到和下载的: 所以涉及私密信息的,需要 ...
- GRASP (职责分配原则)
要学习设计模式,有些基础知识是我们必须要先知道的,设计模式是关于类和对象的一种高效.灵活的使用方式,也就是说,必须先有类和对象,才能有设计模式的用武之地,否则一切都是空谈,那么类和对象是从那冒出来的呢 ...
- MVC扩展Url.Action方法解决复杂对象参数问题
1:问题描述 @Url.Action("Index", "Home", new { Key = "Key", Val = new { Nam ...