POJ 1129 Channel Allocation
来源:互联网 发布:警用强光手电 淘宝 编辑:程序博客网 时间:2024/04/29 05:41
题目链接:http://poj.org/problem?id=1129
题目描述:
这题可以看成就是一个涂色问题,给定一个无向图,节点最多为26个,然后给每个节点涂色,相邻的不能涂相同的颜色,其实就可以对每一个节点开始模拟涂色,1号还是,看是否合适即可。
<span style="font-size:18px;">#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std ;const int MAXN = 30 ;bool val[MAXN][MAXN] ;int col[MAXN], n ;//bool judge(int a, int b){for( int i = 0; i < n; i++ ){if( i == a )continue ;if( val[a][i] && col[i] == b )return false ;}return true ;}//void cal(){int res = 0 ;for( int i = 0; i < n; i++ ){for( int j = 0; j < 26; j++ ){if( judge(i, j) ){col[i] = j ;res = max(j, res) ;break ;} }}cout << res+1 ;if( res == 0 )cout << " channel needed.\n" ;else cout << " channels needed.\n" ;}//int main(){//freopen("1234.txt", "r", stdin) ;//freopen("out.txt", "w", stdout) ;while( scanf("%d",&n) != EOF && n ){memset(val, false, sizeof(val)) ;memset(col, -1, sizeof(col)) ;char ch ;ch = getchar() ;for( int i = 0; i < n; i++ ){scanf("%c:", &ch) ;int num = ch - 'A' ;ch = getchar() ;while( ch != '\n' ){val[num][ch-'A'] = true ; ch = getchar() ;}}cal() ;}return 0 ;}</span>
0 0
- 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
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- poj 1129 Channel Allocation
- POJ 1129 Channel Allocation
- Channel Allocation(poj 1129 )
- poj 1129 Channel Allocation
- POJ 1129--Channel Allocation
- poj 1129 Channel Allocation
- POJ 1129 Channel Allocation
- 数字模式的识别
- emacs 配置
- ZooKeeper介绍、使用及原理
- mysql提高数据插入效率
- 日子 (汪国真)
- POJ 1129 Channel Allocation
- linux java安装
- window 下 pycharm的安装以及 教程(一)安装和首次使用
- 记于2015/01/03
- 小黄人软件淘宝旗舰店 ---程序源码,定制专家手机:18910620895 旺旺:chenhao0568 QQ:345139427
- Unity3D面试ABC
- 测试注意点及发展之路
- 求n维空间点的距离(改进版)
- JVM监控命令与工具(二) jstat