每日一题(2):poj1129: Channels Allocation
来源:互联网 发布:数据透视表最大行 编辑:程序博客网 时间:2024/05/16 12:22
1. 关于复杂度的计算。没有用四色定理。直接暴力加剪枝。
2. 148K 0MS, 要求:Time Limit: 1000MS Memory Limit: 10000K
3. 主要是原来无从下手。后来看了点击打开链接才有了思路。主要就是map二维函数和color一维,给了自己思路。map的第一个参数用本点,然后二维是相邻点。color则是记录每个点的颜色。
4. 输入值得注意。
2. 148K 0MS, 要求:Time Limit: 1000MS Memory Limit: 10000K
3. 主要是原来无从下手。后来看了点击打开链接才有了思路。主要就是map二维函数和color一维,给了自己思路。map的第一个参数用本点,然后二维是相邻点。color则是记录每个点的颜色。
4. 输入值得注意。
5. dfs与前面略有不同。第二次dfs不需要考虑回溯了。
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int ans;bool map[26][26];int color[26];bool isFind;int num;//判断此id可否用otal代表的颜色bool isOK(int id, int total){ for(int i = 0;i < num; i++) { if(map[id][i]&&color[i]==total) return false; } return true;}//深搜,用id号和目前的颜色总数做参数。bool dfs(int id, int total){ //递归结束条件 if(id>=num) { return true; } //在之前已经用过的颜色里面选取可以用的。 for(int i = 1; i<=total; i++) { if(isOK(id,i)) { color[id] = i; if(dfs(id+1,total)) return true; color[id]=0; } } //在上面找不到,就直接用新的。 color[id]=total+1; ans++; if(dfs(id+1,total+1)) return true; return false;}int main(){ //从文件读入 // freopen("channel.txt","r",stdin); while(scanf("%d",&num)&&num) { //空行 getchar(); memset(map,false,sizeof(map)); memset(color,0,sizeof(color)); char s[26]; for(int i = 0; i < num; i++) { gets(s); for(int j = 2; s[j]!='\0'; j++) { map[s[0]-'A'][s[j]-'A']=true; } } isFind = false; ans = 1; dfs(0,1); if(ans==1) { printf("1 channel needed.\n"); }else printf("%d channels needed.\n",ans); }}
。
0 0
- 每日一题(2):poj1129: Channels Allocation
- POJ1129 Channel Allocation(点着色问题)
- poj1129——Channel Allocation(dfs)
- POJ1129—Channel Allocation
- POJ1129--Channel Allocation
- POJ1129 Channel Allocation
- poj1129 Channel Allocation
- POJ1129 Channel Allocation
- POJ1129-Channel Allocation
- POJ1129 Channel Allocation DFS
- POJ1129 Channel Allocation
- POJ1129 Channel Allocation(AC)
- poj1129 Channel Allocation
- poj1129 Channel Allocation
- POJ1129-Channel Allocation
- HDU1373&&POJ1129-Channel Allocation
- POJ1129 Channel Allocation
- poj1129-Channel Allocation(搜索练习6-染色)
- 进程与线程区别
- HP-UX系统诊断日志
- github,怎么向开源项目贡献自己的代码和协作
- 矩阵特征值分解与奇异值分解含义解析及应用
- 当当网新用户注册界面——界面源码
- 每日一题(2):poj1129: Channels Allocation
- REWRWE
- 微服务理论与实践(五)-微服务之间的交互
- Centos7手动部署Openstack Mitaka版安装配置--(五)安装nova计算服务
- arm 串口pe中断的出现
- [Java]_[JDK1.8新特性]
- linux怎么查询cpu核心数
- mybatis:resultMap
- java:判断list为空