快速切题 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 ...
随机推荐
- Eclipse的快捷键使用总结
最近一直在使用Idea开发项目,导致之前一直使用的Eclipse快捷键忘记的差不多了,现在稍微整理了一些,方便以后可以快速切换回来. 常用的Eclipse快捷键总结: Ctrl+S 保存当前正在编辑的 ...
- 骗访问量的机房人物列传by xMinh
作者:$xMinh$ 人物列传·Refun(Aufun,虚凡,人赢) 机房最人赢的人赢,上过表白墙的男人 在宿舍公然开设情感讲座和人赢培训班,教学成果显著,他的徒弟要么gay了要么凉了 认识的人极其广 ...
- testlogin
!/usr/bin/env python coding:utf-8 import requests import unittest import json,urllib class testlogin ...
- Cocos2d-x学习笔记(一)环境搭建与项目创建
可运行的代码可以说明一切问题. 环境需安装VS201x + Python2.7 + Cocos2d-x-2.2.5.(Linux下参考链接:http://www.cocos2d-x.org/wiki/ ...
- DATEDIFF 和 DATEADD
/* DATEDIFF函数计算两个日期之间的小时.天.周.月.年等时间间隔总数 语法 DATEDIFF(interval, date1, date2[, firstdayofweek[, firstw ...
- 分析 HTML 代码并提取数据
在前面的内容中,我们已经学习了 HTML.CSS 和 XPath 的基础知识.从真实世界的网页中获取数据,关键在于如何编写合适的 CSS 或者 XPath 选择器.本节介绍一些确定选择器的简单方法.假 ...
- python将xml转换成json数据
# -*- coding: utf-8 -*- import requests import xmltodict import json def get_response(request_url): ...
- 《剑指offer》第三十三题(二叉搜索树的后序遍历序列)
// 面试题33:二叉搜索树的后序遍历序列 // 题目:输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果. // 如果是则返回true,否则返回false.假设输入的数组的任意两个数字都 ...
- URAL 1183 Brackets Sequence
URAL 1183 思路:区间dp,打印路径,详见http://www.cnblogs.com/widsom/p/8321670.html 代码: #include<iostream> # ...
- Codeforces 847I - Noise Level
847I - Noise Level 思路:bfs. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...