poj 1129 Channel Allocation(点的着色)
来源:互联网 发布:淘宝10元包邮活动 编辑:程序博客网 时间:2024/06/13 22:02
Channel Allocation
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 12835 Accepted: 6577
Description
When 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 nearby repeaters 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 of channels required.
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
The 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 alphabet starting 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: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.
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
For 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 channels is in the singular form when only one channel is required.
Sample Input
2A:B:4A:BCB:ACDC:ABDD:BC4A:BCDB:ACDC:ABDD:ABC0
Sample Output
1 channel needed.3 channels needed.4 channels needed.
Source
Southern African 2001
题意就是求图的色数 枚举每个点 贪心
#include <cstdio>#include <iostream>#include <cstring>#include <cmath>#include <algorithm>#include <string.h>#include <string>#include <vector>#include <queue>#define MEM(a,x) memset(a,x,sizeof a)#define eps 1e-8#define MOD 10009#define MAXN 10010#define INF 99999999#define ll __int64#define bug cout<<"here"<<endl#define fread freopen("ceshi.txt","r",stdin)#define fwrite freopen("out.txt","w",stdout)using namespace std;void read(int &x){ char ch; x=0; while(ch=getchar(),ch!=' '&&ch!='\n') { x=x*10+ch-'0'; }}int edge[30][30];char ch[30];int ans,b[30],c[30];//ans 代表所使用的颜色的数量 c代表各个顶点所使用的颜色 b代表 该颜色有木有被使用int n;void color(){ for(int i=0;i<n;i++) { MEM(b,0); for(int j=0;j<n;j++) { if(edge[i][j]&&c[j]!=-1) { b[c[j]]=1; } } int k; for(k=0;k<=i;k++) { if(!b[k]) break; } c[i]=k; } for(int i=0;i<n;i++) { if(ans<c[i]) ans=c[i]; } ans++;}int main(){ //fread; while(scanf("%d",&n)!=EOF) { if(n==0) break; MEM(edge,0); MEM(c,-1); for(int i=0;i<n;i++) { scanf("%s",ch); int len=strlen(ch); for(int j=0;j<len-2;j++) edge[i][ch[j+2]-'A']=1; } ans=0; color(); if(ans==1) printf("%d channel needed.\n",ans); else printf("%d channels needed.\n",ans); } return 0;}
0 0
- poj 1129 Channel Allocation(点的着色)
- POJ 1129-Channel Allocation(顶点着色)
- POJ 1129 Channel Allocation(图的着色问题)
- POJ1129 Channel Allocation(点着色问题)
- poj 1129 Channel Allocation(四色定理+着色问题)
- poj 1129 Channel Allocation(图着色,DFS)
- POJ 1129 Channel Allocation 着色问题 dfs
- Channel Allocation(POJ 1129)
- POJ 1129 Channel Allocation DFS搜索 着色问题
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- poj 1129Channel Allocation
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- collectionView
- 指针函数与函数指针
- 1.8
- 015:字符串:格式化
- 【Qt编程】基于Qt的词典开发系列<一>--词典框架设计及成品展示
- poj 1129 Channel Allocation(点的着色)
- Win7下VC6打开文件报错导致其崩溃的解决办法
- Python学习之路13——字符串2
- bzoj 1251/tyvj p2195 序列终结者
- NSSearchPathForDirectoriesInDomains用法
- 黑马程序员JAVA 070---080 小结
- Direct3D 12 尝鲜(二): Fence
- Android血泪史之Unable to instantiate activity ComponentInfo
- 上传控件 WebUploader