Channel Allocation 贪心涂色
1 #include <iostream>
2 #include <cstdio>
3 #include <cstring>
4 #include <cmath>
5 #include <algorithm>
6 #include <string>
7 #include <vector>
8 #include <set>
9 #include <map>
10 #include <stack>
11 #include <queue>
12 #include <sstream>
13 #include <iomanip>
14 using namespace std;
15 typedef long long LL;
16 const int INF = 0x4fffffff;
17 const double EXP = 1e-5;
18 const int MS = 28;
19 const int SIZE = 100005;
20
21
22 int edges[MS][MS];
23 char str[MS];
24 int used[MS];
25 int color[MS];
26 int ans,n;
27
28 void greedy()
29 {
30 for(int i=0;i<n;i++)
31 {
32 memset(used,0,sizeof(used));
33 for(int j=0;j<n;j++)
34 {
35 if(edges[i][j]&&color[j]!=-1)
36 used[color[j]]=1;
37 }
38 int k;
39 for(k=0;k<i;k++)
40 {
41 if(!used[k])
42 break;
43 }
44 color[i]=k;
45 }
46 ans=0;
47 for(int i=0;i<n;i++)
48 if(ans<color[i])
49 ans=color[i];
50 ans++;
51 }
52
53
54 int main()
55 {
56 while(scanf("%d",&n)&&n)
57 {
58 memset(color,0xff,sizeof(color));
59 memset(edges,0,sizeof(edges));
60 for(int i=0;i<n;i++)
61 {
62 scanf("%s",str);
63 int len=strlen(str);
64 for(int j=2;j<len;j++)
65 edges[i][str[j]-'A']=edges[str[j]-'A'][i]=1;
66 }
67 greedy();
68 if(ans==1) // 注意单复数
69 printf("%d channel needed.\n",ans);
70 else
71 printf("%d channels needed.\n",ans);
72 }
73 return 0;
74 }
Channel Allocation 贪心涂色的更多相关文章
- Channel Allocation(DFS)
Channel Allocation Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other) ...
- POJ 1129:Channel Allocation 四色定理+暴力搜索
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13357 Accepted: 68 ...
- poj1129 Channel Allocation(染色问题)
题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...
- POJ 1129 Channel Allocation(DFS)
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 13173 Accepted: 67 ...
- 1260: [CQOI2007]涂色paint
Description 假设你有一条长度为5的木版,初始时没有涂过任何颜色.你希望把它的5个单位长度分别涂上红.绿.蓝.绿.红色,用一个长度为5的字符串表示这个目标:RGBGR. 每次你可以把一段连续 ...
- poj1129 Channel Allocation
Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14361 Accepted: 73 ...
- 【BZOJ-1260】涂色paint 区间DP
1260: [CQOI2007]涂色paint Time Limit: 30 Sec Memory Limit: 64 MBSubmit: 1147 Solved: 698[Submit][Sta ...
- 并查集(涂色问题) HDOJ 4056 Draw a Mess
题目传送门 题意:给出一个200 * 50000的像素点矩阵,执行50000次操作,每次把一个矩形/圆形/菱形/三角形内的像素点涂成指定颜色,问最后每种颜色的数量. 分析:乍一看,很像用线段树成段更新 ...
- 迭代加深搜索 POJ 1129 Channel Allocation
POJ 1129 Channel Allocation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 14191 Acc ...
随机推荐
- Sqoop 安装部署
1. 上传并解压 Sqoop 安装文件 将 sqoop-1.4.7.bin__hadoop-2.6.0.tar.gz 安装包上传到 node-01 的 /root/ 目录下并将其解压 [root@no ...
- linux 详解useradd 命令基本用法
linux 详解useradd 命令基本用法 时间:2019-03-24 本文章向大家介绍linux 详解useradd 命令基本用法,主要包括linux 详解useradd 命令基本用法使用实例.应 ...
- zabbix监控之邮件报警通知
zabbix官网的操作指南:https://www.zabbix.com/documentation/4.0/zh/manual 首先我们需要创建一个需要被监控的主机,并设置相应的监控项.当监控项收集 ...
- shell初学之nginx(域名)
创建两个以域名区分的虚拟网站: 1 #!/bin/bash 2 curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/ ...
- Linux进阶之Linux破解密码、yum源配置、防火墙设置及源码包安装
一.老师语录: 所有要求笔试的公司都是垃圾公司 笔试(是考所有的涉及到的点) 要有自己的卖点.专长(给自己个标签)(至少一个) 生产环境中,尽量使用mv(mv到一个没用的目录下),少使用rm 二.防火 ...
- python基础之pip、.pyc、三元运算、进制、一切皆对象、可变与不可变类型
一.pip(下载工具==yum) 1.重点(必须掌握的) 列出已安装的包 pip list 安装要安装的包 pip install xxx 安装特定版本 pip install django==1.1 ...
- lua type 获取 类型
lua中的类型作一小记 print(type("Hello world")) --> string print(type(10.4*3)) --> number pri ...
- Java常用集合笔记
最近事情比较少,闲暇之余温习巩固一下Java的一些基础知识,并做一些笔记, Java常用集合, 主要参考的这篇文章:Java常用集合 ArrayList/Vertor 1. ArrayList 的主要 ...
- Python+Selenium学习笔记9 - 警告框处理
如下图所示,这种窗口是不能通过前端工具对其进行定位的,这里可以通过switch_to_alert()方法去接受这个弹窗 1 # coding = utf-8 2 3 from selenium imp ...
- descriptor 'decode' requires a 'bytes' object but received a 'NoneType'
记录在使用python过程中踩的坑------ 使用xlwt库对excel文件进行保存时报错 descriptor 'decode' requires a 'bytes' object but rec ...