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. top命令查看CPU状态信息:%us、%sy、%ni、%id、%wa、%hi、%si、%st 表示的是什么意思

    Linux CPU负载状态:%us/%sy/%ni/%id/%wa/%hi/%si/%st含义 2018-08-26 分类:Linux 评论(0)   缙哥哥发现用了雅黑的探针,在 Linux 的 C ...

  2. 通用PE u盘装Ghost Win7系统教程

    通用PE u盘装Ghost Win7系统教程 导读 通用pe工具箱是现在最老牌的的U盘装系统和维护电脑的专用工具之一,一键式制作.操作简单便捷,几乎100%支持所有U盘,不再为装机烦恼们,抓紧时间下载 ...

  3. 电路调试检测维修总结积累 20181015 板子:3060-A

    今天在检修一块3060-A电路板时 发现   3.3V烫 但是3.3V路上的电容并没有短路 于是拆单片机   拆RS232EN  拆  FM24V 最后发现  原来是  1117-3.3  处的33U ...

  4. 重新整理 .net core 实践篇————配置系统——军令(命令行)[六]

    前言 前文已经基本写了一下配置文件系统的一些基本原理.本文介绍一下命令行导入配置系统. 正文 要使用的话,引入Microsoft.extensions.Configuration.commandLin ...

  5. Java基础之概述

    1. 什么是程序 程序是计算机执行某些操作或解决某个问题而编写的一系列有序指令的集合 2. Java三大版本 Java SE 标准版 Java EE 企业版 Java ME 小型版 3. Java重要 ...

  6. Go基础结构与类型05---程序运算

    package main import ( "fmt" "math" ) func main() { /*加减乘除,求余*/ fmt.Println(" ...

  7. 并发编程-Condition

    Condition 一个Lock中应该绑定一个Condition对象.Condition是Java提供用来实现等待/通知的类. 我们知道Object对象提供了wait.waitAll.notify.n ...

  8. 目标检测中的anchor-based 和anchor free

    目标检测中的anchor-based 和anchor free 1.  anchor-free 和 anchor-based 区别 深度学习目标检测通常都被建模成对一些候选区域进行分类和回归的问题.在 ...

  9. TensorFlow实现多层感知机函数逼近

    TensorFlow实现多层感知机函数逼近 准备工作 对于函数逼近,这里的损失函数是 MSE.输入应该归一化,隐藏层是 ReLU,输出层最好是 Sigmoid. 下面是如何使用 MLP 进行函数逼近的 ...

  10. 开放神经网络交换(ONNX)工具

    开放神经网络交换(ONNX)工具 开放神经网络交换(ONNX)是一个开放的生态系统,它使人工智能开发人员能够在项目发展过程中选择正确的工具.ONNX为人工智能模型提供了一种开源格式,包括深度学习和传统 ...