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 贪心涂色的更多相关文章

  1. Channel Allocation(DFS)

    Channel Allocation Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) ...

  2. POJ 1129:Channel Allocation 四色定理+暴力搜索

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13357   Accepted: 68 ...

  3. poj1129 Channel Allocation(染色问题)

    题目链接:poj1129 Channel Allocation 题意:要求相邻中继器必须使用不同的频道,求需要使用的频道的最少数目. 题解:就是求图的色数,这里采用求图的色数的近似有效算法——顺序着色 ...

  4. POJ 1129 Channel Allocation(DFS)

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 13173   Accepted: 67 ...

  5. 1260: [CQOI2007]涂色paint

    Description 假设你有一条长度为5的木版,初始时没有涂过任何颜色.你希望把它的5个单位长度分别涂上红.绿.蓝.绿.红色,用一个长度为5的字符串表示这个目标:RGBGR. 每次你可以把一段连续 ...

  6. poj1129 Channel Allocation

    Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14361   Accepted: 73 ...

  7. 【BZOJ-1260】涂色paint 区间DP

    1260: [CQOI2007]涂色paint Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 1147  Solved: 698[Submit][Sta ...

  8. 并查集(涂色问题) HDOJ 4056 Draw a Mess

    题目传送门 题意:给出一个200 * 50000的像素点矩阵,执行50000次操作,每次把一个矩形/圆形/菱形/三角形内的像素点涂成指定颜色,问最后每种颜色的数量. 分析:乍一看,很像用线段树成段更新 ...

  9. 迭代加深搜索 POJ 1129 Channel Allocation

    POJ 1129 Channel Allocation Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14191   Acc ...

随机推荐

  1. MySQL配置HeartBeat实现心跳监控和浮动IP

    1. 初始化环境配置 /sbin/chkconfig --add mysqld /sbin/chkconfig mysqld on ln -s /usr/local/mysql/bin/mysql / ...

  2. Linux_WEB服务基础概念

    一.HTTPD简介 1️⃣:httpd是Apache超文本传输协议(HTTP) 服务器的主程序.被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池. 2️⃣:通常,httpd不应该 ...

  3. 03丨认识文档数据库MongoDB

  4. Jmeter(四十七) - 从入门到精通高级篇 - 分布式压测部署之负载机的设置(详解教程)

    1.简介 千呼万唤始出来,这一篇感觉写了好久,总想写的清楚明白简洁,但是还是洋洋洒洒写了好多,希望大家喜欢吧!本来打算将这一篇文章是放在性能测试中讲解和分享的,但是有的童鞋或者小伙伴们私下问的太多了, ...

  5. ntp导致的时钟回拨

    ntp导致的时钟回拨 时钟回拨 我们的服务器时间校准一般是通过ntp进程去校准的.但由于校准这个动作,会导致时钟跳跃变化的现象. 而这种情况里面,往往回拨最能引起我们的困扰,回拨如下所示: 会引起什么 ...

  6. [Windows] 将中文输入法热键改回Ctrl+Space

    造冰箱的大熊猫@cnblogs 2021/6/6 之前因为Code Composer Studio的缘故将Windows XP上的中英文切换热键从Ctrl+Space改为了Ctrl+Shift+Spa ...

  7. 《MySQL面试小抄》索引考点一面总结

    <MySQL面试小抄>索引考点一面总结 我是肥哥,一名不专业的面试官! 我是囧囧,一名积极找工作的小菜鸟 囧囧表示:面试最怕的就是面试官问的知识点太笼统,自己无法快速定位到关键问题点!!! ...

  8. Mobileye高级驾驶辅助系统(ADAS)

    Mobileye高级驾驶辅助系统(ADAS) Mobileye is the global leader in the development of vision technology for Adv ...

  9. AI基础架构Pass Infrastructure

    AI基础架构Pass Infrastructure Operation Pass OperationPass : Op-Specific OperationPass : Op-Agnostic Dep ...

  10. Java面试题:==运算符与equals方法的区别

    据说这个面试题目,80%的程序员都会理直气壮的回答错误!! 一: ==运算符 如果比较的是基本数据类型,则直接比较数值是否相等,返回值为"true or false" 如果比较的是 ...