http://poj.org/problem?id=1129
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 9779 | Accepted: 4983 |
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.
Source
题意:给出一幅图,求最小染色数可以使得相邻两点不同色。即图的着色问题。
题目的描述部分翻译成中文大概就是:
当一个广播电台在一个非常大的地区,广播站会用中继器来转播信号以使得每一个接收器都能接收到一个强烈的信号。然而,每个中继器必须慎重选择使用,使相邻的中继器不互相干扰。如果相邻的中继器使用不同的频道,那么就不会相互干扰。
由于无线电频道是一有限的,一个给定的网络所需的中继频道数目应减至最低。编写一个程序,读取一个中继网络,然后求出需要的最低的不同频道数。
如果用图的术语来讲就是一个有N个节点的无向图,要求对每个节点进行染色,使得相邻两个节点颜色都不同,问最少需要多少种颜色?
那么题目就变成了一个经典的图的染色问题。
对于这题数据范围很小(节点最多26个),所以使用普通的暴力搜索法即可。
由四色定理可以得知最多需要4种颜色,所以可以枚举颜色的数目,然后判断是否可以染色。
解题思路:
推荐博文:http://blog.csdn.net/lyy289065406/article/details/6647986
还有一种暴力解法http://blog.sina.com.cn/s/blog_626489680100kbon.html、
这个也不错http://blog.163.com/boatswain@126/blog/static/1693964122010836141328/
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
bool map[30][30];
char s[30];
int color[30],color_count;
int n,mincolor=999999,flag;
bool isok(int dept,int
{
}
void dfs(int depth)
{
}
int main()
{
}