POJ 1129
2012-07-01 11:30
246 查看
此题的本质问题就是对无向图的着色,使颜色使用最少的问题
#include <stdio.h> #define maxn 27 typedef struct Node { int next[maxn]; int tot; }node; int main() { int n; while(scanf("%d",&n)&&n!=0) { getchar();//吸收回车 node map[maxn]; int i,j,k; for(i=0;i<n;i++)//建图 { map[i].tot=0; getchar();//吸收每行的首字母,因为是字典序输入 getchar();//吸收冒号 char c; while((c=getchar())!='\n') { int t=c-'A'; map[i].next[map[i].tot++]=t; } } int color[maxn]={0};//每个节点的颜色 int mc=1;//所用颜色总数 for(i=0;i<n;i++)//对图的节点进行染色 { int visit[maxn]={0};//标记邻节点的颜色 for(j=0;j<map[i].tot;j++) { if(color[j]) visit[color[j]]=1; } for(k=1;k<maxn;k++) { if(!visit[k]) { color[i]=k; break; } } if(color[i]>mc) mc=color[i]; } if(mc==1) printf("1 channel needed.\n"); else printf("%d channels needed.\n",mc); } return 0; }
相关文章推荐
- POJ Channel Allocation 1129(dfs+四色定理)
- POJ1129 Channel Allocation
- poj 1129
- poj 1129(DFS+四色定理)
- poj 1129(dfs+图的四色定理)
- POJ 1129
- poj 1129 Channel Allocation
- POJ 1129 平面图顶点染色
- Channel Allocation (poj 1129 dfs)
- POJ-1129 Pie 解题报告
- POJ 1129
- POJ-1129 Channel Allocation 解题报告
- POJ 1129
- 【poj 1129】Channel Allocation 题意&题解&代码(C++)
- Channel Allocation (poj 1129 dfs)
- POJ 1129 Channel Allocation
- POJ1129 Channel Allocation——染色问题 暴搜
- POJ 1129 Channel Allocation
- poj 1129 -- Channel Allocation
- poj 1129 Channel Allocation (dfs)