poj-1129 Channel Allocation
来源:互联网 发布:java并发编程的艺术 编辑:程序博客网 时间:2024/06/18 12:19
题意:广播电台分布在一个很大的地方,每个广播电台为了受到更强的信号会使用一个中继器,而每个相邻的广播电台之间如果使用相同的中继器会干扰信号。问最少需要多少个中继器可以让所有广播电台使用并不相互影响。
思路:该题可以模拟成涂色问题,每个相邻的区域不能涂相同的颜色。这也就会想到著名的四色原理。根据四色原理对每个区域只需要枚举4种情况即可。每个点只枚举一次,DFS里其实并没有回溯的过程,用循环写也是可以的。
#include <iostream>#include <algorithm>#include <cstdio>#define INF 0x3f3f3f3f#define mod 1000000007using namespace std;int mp[27][27];int vis[27];int n,flag;void DFS(int x){ int i,j; if(x==n+1) { int maxx=0; flag=1; for(i=1;i<=n;i++) { if(vis[i]>maxx) maxx=vis[i]; } if(maxx==1) printf("1 channel needed.\n"); else printf("%d channels needed. \n",maxx); return ; } for (i=1;i<=4;i++) { for(j=1;j<=n;j++) { if(mp[x][j]&&vis[j]==i) break; } if(j==n+1) { vis[x]=i; DFS(x+1); if(flag) return; } }}int main(){ char str[30]; int i,j; while(scanf("%d",&n),n) { memset(vis,0,sizeof(vis)); memset(mp,0,sizeof(mp)); flag=0; int len; for(i=0;i<n;i++) { scanf("%s",str); len=strlen(str); int x=str[0]-'A'+1; for (j=2;j<len;j++) { int y=str[j]-'A'+1; mp[x][y]=1; } } DFS(1); } return 0;}
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
- Webx增加StaffLoginValve
- LeetCode题解:Plus One
- UIView实现动画效果
- 快速理解RequireJs
- 错误:'/Library/Java/JavaVirtualMachines/jdk1.8.0_31.jdk/Contents/Home/bin/java'' finished with non-zer
- poj-1129 Channel Allocation
- Network Saboteur(POJ_2531)
- 解读jquery源码时记录的一些知识点
- Spark入门实战系列--6.SparkSQL(上)--SparkSQL简介
- TwemProxy(nutcracker)参数选项及配置解析
- unity3d GameCenter的使用
- 数据库性能优化一:数据库自身优化(大数据量)
- 关于Oracle ADF 11g的传值给bounded task flow
- Echarts 单序列数据颜色color交替实现