快速切题 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 ...
随机推荐
- noip2015 day1
不解释,很简单,直接按照题目的方法构造就行了 Code #include<iostream> #include<cstdio> #include<cctype> # ...
- 关于Qt跨线程调用IO子类的理解
一.疑问 突然想到,类似于QTcpsocket和QSerialport这类对象,如果是在A线程中new的,那就不能在其他线程中访问.我一般是这样做的: 封装一个QObject子类,放这些对象进去,然后 ...
- Metasploit应用举例
本篇文章包含以下几方面内容: 1.Metasploit端口扫描: 2.用其他模块 3.metasploit smb获取系统信息 4.Metsploit服务识别 5.ftp识别: 6.metasploi ...
- 搭建最新版本的Android开发环境
只为成功找方法,不为失败找借口! Android开发学习总结(一)——搭建最新版本的Android开发环境 最近由于工作中要负责开发一款Android的App,之前都是做JavaWeb的开发,Andr ...
- 【第十二章】 springboot + mongodb(复杂查询)
简单查询:使用自定义的XxxRepository接口即可.(见 第十一章 springboot + mongodb(简单查询)) 复杂查询:使用MongoTemplate以及一些查询条件构建类(Bas ...
- 论文笔记——MobileNets(Efficient Convolutional Neural Networks for Mobile Vision Applications)
论文地址:MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications MobileNet由Go ...
- 【TCP/IP详解 卷一:协议】第十七章 TCP:传输控制协议
本章作为TCP的入门章节,简单的概述了一些TCP的知识,和TCP数据报的首部格式. TCP 最重要的特性:reliable. 17.1 引言 本章介绍的是 TCP为应用层提供的服务. 17.2 TCP ...
- UVa 1631 密码锁
https://vjudge.net/problem/UVA-1631 题意: 有一个n位密码锁,每位都是0~9,可以循环旋转.每次可以让1~3个相邻数字同时往上或者往下转一格.输入初始状态和终止状态 ...
- Varnish 一般是放在 Nginx 前面还是后面的?
1.varnish官网有写. 如果用ssl前面肯定得有nginx. 如果没有ssl看你实际需求.可以varnish,然后nginx,然后app. 看怎么设计了. 2.Varnish 通常是在两种情况下 ...
- shell 布尔运算符
布尔运算符 下表列出了常用的布尔运算符,假定变量 a 为 10,变量 b 为 20: 运算符 说明 举例 ! 非运算,表达式为 true 则返回 false,否则返回 true. [ ! false ...