poj 1129 Channel Allocation(四色定理+着色问题)
2013-09-13 13:22
543 查看
Channel Allocation
DescriptionWhen a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully chosen so that nearbyrepeaters do not interfere with one another. This condition is satisfied if adjacent repeaters use different channels.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 ofchannels required.InputThe input consists of a number of maps of repeater networks. Each map begins with a line containing the number of repeaters. This is between 1 and 26, and the repeaters are referred to by consecutive upper-case letters of the alphabetstarting 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:BCDHwhich 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 linehas the formA: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.OutputFor each map (except the final one with no repeaters), print a line containing the minumum number of channels needed so that no adjacent channels interfere. The sample output shows the format of this line. Take care that channelsis in the singular form when only one channel is required.Sample Input
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 10994 | Accepted: 5645 |
2 A: B: 4 A:BC B:ACD C:ABD D:BC 4 A:BCD B:ACD C:ABD D:ABC 0Sample Output
1 channel needed. 3 channels needed. 4 channels needed.
题意:给定与每个点相邻的点,求着色问题。
思路:利用了四色定理.
AC代码:
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <queue>#include <vector>#include <cmath>#include <map>#include <cstdlib>#define L(rt) (rt<<1)#define R(rt) (rt<<1|1)#define ll long long#define eps 1e-6using namespace std;const int maxn=30;int n;int color[maxn];bool vis[maxn];vector<int>G[maxn];int main(){char s[50];while(scanf("%d",&n),n){for(int i=1;i<=n;i++) G[i].clear();for(int i=1;i<=n;i++){scanf("%s",s);int u=s[0]-'A'+1;for(int j=2;s[j];j++){int v=s[j]-'A'+1;G[u].push_back(v);}}memset(color,0,sizeof(color));for(int i=1;i<=n;i++){memset(vis,false,sizeof(vis));for(int j=0;j<(int)G[i].size();j++)if(color[G[i][j]]) vis[color[G[i][j]]]=true;for(int j=1;j<=n;j++)if(!vis[j]){color[i]=j;break;}}int ans=1;for(int i=1;i<=n;i++)if(ans<color[i]){ans=color[i];if(ans==4) break;}if(ans==1) printf("1 channel needed.\n");else printf("%d channels needed.\n",ans);}return 0;}[/code]
相关文章推荐
- POJ 1129 Channel Allocation DFS搜索 着色问题
- poj 1129(ID-DFS四色定理)
- POJ 1129 Channel Allocation(图的着色问题)
- POJ 1129 图的四色定理
- POJ 1129-Channel Allocation(四色定理+迭代深搜)
- POJ 1129 Channel Allocation DFS+四色问题优化
- poj 1129(图的着色问题)
- ACM:着色问题 poj 1129
- POJ 1129:Channel Allocation 四色定理+暴力搜索
- poj 1129 四色定理
- POJ 1129:Channel Allocation 四色定理+暴力搜索
- poj 1129 DFS+四色问题 Channel Allocation
- POJ 1129 Channel Allocation DFS搜索 着色问题
- POJ 1129 四色问题 暴力搜索
- POJ 1129 Channel Allocation(暴力搜--涂色问题)
- POJ 1419--Graph Coloring(最大团求二着色问题)
- 【POJ】1129【涂色问题】【Channel Allocation】
- POJ 1129 Channel Allocation 平面图染色问题
- poj 1129 Channel Allocation(点的着色)
- POJ1129 Channel Allocation——染色问题 暴搜