poj 1129 Channel Allocation(图着色,DFS)
来源:互联网 发布:算法mobi 编辑:程序博客网 时间:2024/05/22 13:10
题意:
N个中继站,相邻的中继站频道不得相同,问最少需要几个频道。
输入输出:
Sample Input
2A:B:4A:BCB:ACDC:ABDD:BC4A:BCDB:ACDC:ABDD:ABC0
Sample Output
1 channel needed.3 channels needed.4 channels needed.
题意抽象+思路:
一张有N个点的无向图,对每个点进行染色,相邻的点颜色不得一致,最少需多少种颜色。DFS即可。
代码:
<span style="font-family:Microsoft YaHei;">int nmax;bool mapp[30][30], is[30], coll[30];int col[30];void dfs(int u){ mem(coll,false); rep(i,0,25){ if(u!=i && mapp[u][i] && col[i]){ coll[col[i]] = true; } } rep(i,26,1) if(coll[i]){ nmax = i; break; } rep(i,1,26) if(!coll[i]){ col[u] = i; nmax = max(nmax,i); break; } rep(i,0,25){ if(u!=i && mapp[u][i] && !col[i]) dfs(i); }}int main(){ int n; char s[100]; while(scanf("%d",&n),n){ mem(mapp,false); mem(is,false); mem(col,0); while(n--){ scanf("%s",s); int l=strlen(s); is[s[0]-'A'] = true; rep(i,2,l-1){ mapp[s[0]-'A'][s[i]-'A'] = true; mapp[s[i]-'A'][s[0]-'A'] = true; is[s[i]-'A'] = true; } } nmax = 0; rep(i,0,25){ if(is[i] && !col[i]) dfs(i); //对i进行染色,并从i开始把那个集合中的点都染上色 } if(nmax==1) printf("%d channel needed.\n",nmax); else printf("%d channels needed.\n",nmax); }}</span>
0 0
- poj 1129 Channel Allocation(图着色,DFS)
- POJ 1129 Channel Allocation 着色问题 dfs
- POJ 1129-Channel Allocation(顶点着色)
- POJ 1129 Channel Allocation(图的着色问题)
- POJ 1129 Channel Allocation DFS搜索 着色问题
- POJ 1129 Channel Allocation (DFS)
- POJ 1129 Channel Allocation(DFS)
- poj 1129 Channel Allocation(DFS减枝)
- POJ 1129 Channel Allocation(dfs)
- poj 1129 Channel Allocation (DFS 图的染色问题)
- Channel Allocation (poj 1129 dfs)
- poj 1129 Channel Allocation (dfs)
- poj 1129 Channel Allocation(dfs)
- poj 1129 Channel Allocation(四色定理+着色问题)
- poj 1129 Channel Allocation(点的着色)
- POJ 1129 Channel Allocation(dfs模拟图的上色问题)
- poj 1129Channel Allocation(染色问题, DFS)
- POJ 1129 Channel Allocation dfs(四色定理)
- fopen 参数详解
- hdu5009 Paint Pearls DP
- 东软学习,strut2初级学习马士兵的部分截图和笔记(一)
- AOP技术应用和研究--OOP
- RQNOJ:PID5 能量项链
- poj 1129 Channel Allocation(图着色,DFS)
- 教你透彻了解红黑树
- JVM原理
- 进程和线程的区别和联系
- sqlite3使用简介
- HDU-1257-最少拦截系统
- Leetcode_num2_Maximum Depth of Binary Tree
- Lua的IO操作
- 排队 约瑟夫环