POJ - 1129 Channel Allocation(染色问题)

2023-11-19

When a radio station is broadcasting over a very large area, repeaters are used to retransmit the signal so that every receiver has a strong signal. However, the channels used by each repeater must be carefully chosen so that nearby repeaters do not interfere with one another. This condition is satisfied if adjacent repeaters use different channels.

Since the radio frequency spectrum is a precious resource, the number of channels required by a given network of repeaters should be minimised. You have to write a program that reads in a description of a repeater network and determines the minimum number of channels required.
Input
The input consists of a number of maps of repeater networks. Each map begins with a line containing the number of repeaters. This is between 1 and 26, and the repeaters are referred to by consecutive upper-case letters of the alphabet starting with A. For example, ten repeaters would have the names A,B,C,…,I and J. A network with zero repeaters indicates the end of input.

Following the number of repeaters is a list of adjacency relationships. Each line has the form:

A:BCDH

which indicates that the repeaters B, C, D and H are adjacent to the repeater A. The first line describes those adjacent to repeater A, the second those adjacent to B, and so on for all of the repeaters. If a repeater is not adjacent to any other, its line has the form

A:

The repeaters are listed in alphabetical order.

Note that the adjacency is a symmetric relationship; if A is adjacent to B, then B is necessarily adjacent to A. Also, since the repeaters lie in a plane, the graph formed by connecting adjacent repeaters does not have any line segments that cross.
Output
For each map (except the final one with no repeaters), print a line containing the minumum number of channels needed so that no adjacent channels interfere. The sample output shows the format of this line. Take care that channels is in the singular form when only one channel is required.
Sample Input
2
A:
B:
4
A:BC
B:ACD
C:ABD
D:BC
4
A:BCD
B:ACD
C:ABD
D:ABC
0
Sample Output
1 channel needed.
3 channels needed.
4 channels needed.

题意:

就是用最小的颜色涂满所有区域,且相邻区域不使用同种颜色(这里的相邻就是例如A:BC,A与B、C相邻)

AC代码:

#include<stdio.h>
#include<string.h>
char a[40][40];
int b[40][40];
int c[40],k[40];
int main()
{
	int n,len;
	while(1)
	{
		int i,j,max;
		scanf("%d",&n);
		if(n==0)
			break;
		memset(b,0,sizeof(b));
		
		for(i=0;i<n;i++)
		{
			scanf("%s",a[i]);
			len=strlen(a[i]);
			for(j=2;j<len;j++)
			b[i][a[i][j]-'A']=1;
		}
		//初始化
		c[0] = 0;
		for(i=1;i<n;i++)
		{
			memset(k,0,sizeof(k));
			for(j=0;j<i;j++)
			{
				if (c[j] >=0)
					if(b[i][j])
						k[c[j]]=1;
			}
			for(j=0;j<26;j++)
				if (!k[j])
					break;
			c[i]=j;
		}//这个循环里面就是逐个标记每个点的序号
		max=0;
		for(i=0;i<n;i++)
		{
			if (max<c[i])
				max=c[i];
		}
			if (max==0)
				printf("%d channel needed.\n", max+1);
			else
				printf("%d channels needed.\n", max+1);
	}
	return 0;
} 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

POJ - 1129 Channel Allocation(染色问题) 的相关文章

  • KVM中使用usb设备

    进来学习usb驱动 看到网上都在分析usb skeleton c的驱动框架 就想对其调试一下 看一下其函数调用流程 要想调试usb skeleton 首先需要kvm能够探测到usb设备 其次 在kvm中编译usb skeleton c 最后
  • 深度学习要学多久?半年能入门深度学习吗?

    深度学习的学习时间因个人背景 目标和学习方法而异 不同人可能需要不同的时间来掌握深度学习 深度学习要学多久 通常情况下 入门深度学习可能需要几个月的时间 如果你已经有相关背景知识 学习进度可能会更快 以下是一些因素 可以影响学习深度学习所需
  • 解一元二次方程-Java语言实现

    前言 高考完的那个暑假我就开始自学C语言 那时候通过看视频和 C primer plus 写了一个解一元二次方程的程序 从此走上了吊打大学同班同学的路 但是那次是用C语言写的 如今白云苍狗 我已经不是曾经的那个我了 但我还是一如既往的废物
  • Java的内省技术

    什么是内省 在计算机科学中 内省是指计算机程序在运行时 Run time 检查对象 Object 类型的一种能力 通常也可以称作运行时类型检查 不应该将内省和反射混淆 相对于内省 反射更进一步 是指计算机程序在运行时 Run time 可以

随机推荐

  • 大数据面试-03-大数据工程师面试题

    2 13 简述hadoop的调度器 FIFO schedular 默认 先进先出的原则 Capacity schedular 计算能力调度器 选择占用最小 优先级高的先执行 依此类推 Fair schedular 公平调度 所有的job具有
  • 三十三.二叉树的创建、后序遍历、深度统计。

    include
  • 【视频编码学习】VTM15.0编译运行

    VTM版本 15 0 操作系统 Win10 x64位 IDE Visual Studio 2019 编译器 cmake 利用VS2019运行VTM15 0 前言 一 下载VTM15 0 二 下载安装cmake 1 下载cmake并安装 2
  • Java中的IO流如何理解——精简

    目录 引言 缓冲流 字节缓冲流 字符缓冲流 转换流 字符输入转换流 字符输出转换流 序列化和反序列化 对象序列化 对象反序列化 打印流 Properties 引言 通过前面的简单学习 我们已经能够大致了解了关于文件的操作 但是能够明显感受到
  • mybatis中pagehelper分页、排序

    原文链接 https blog csdn net liuyuanjiang109 article details 78955881 在springboot 结合mybatis 时用到pagehelper 分页工具 并进行分页 排序 其git
  • 安装 mysqldb for python

    1 安装 ssetuptools wget http pypi python org packages 2 6 s setuptools setuptools 0 6c9 py2 6 egg md5 ca37b1ff16fa2ede6e19
  • 常用GIT命令速览,现学也能登堂入室

    系列文章目录 手把手教你安装Git 萌新迈向专业的必备一步 GIT命令只会抄却不理解 看完原理才能事半功倍 常用GIT命令速览 现学也能登堂入室 系列文章目录 一 GIT HELP 1 命令文档 2 简要说明 二 配置 config 1 配
  • minio上传文件报错io.minio.errors.InvalidResponseException: Non-XML response from server

    上传文件报错io minio errors InvalidResponseException Non XML response from server 开发中上传文件到minio遇到问题 上传小于1M的文件成功 上传大于1M的文件失败 检查
  • 《算法图解》第九章动态规划学习心得

    1 背包问题 动态规划先解决子问题 再逐步解决大问题 每个动态规划都从一个网格开始 背包问题的网格如下 网格最初是空的 动态规划就是逐步将网格填满 吉他行 第一个单元格表示背包的容量为1磅 吉他的重量也是1磅 这意味着它能装入背包 因此这个
  • list类型的用法(含列表合并)

    编程中对于链表的处理通常都是比较麻烦的 C 的STL库中提供了list类型 大大方便了我们对链表的处理 不熟悉的小伙伴们快来了解 一定能为你的编程带来益处 list是双向带头循环链表 不同于之前讲过的vector 它不支持随机访问 即下标访
  • python提取两个引号中的内容,怎样用 Python 提取不在双引号的内容?

    三叔2016 11 11 13 30 281楼 import re a Peter d 13tsddgjlsv gt gt bgeghg n desfegeivm x wb rhwrohjow dddeuvb n dwegjosnngwei
  • C语言中的静态函数

    关于C中的static类型的函数是与extern类型相对的 也就是说函数的调用方式并没有改变 只通过这个关键字影响了linker的行为 下面在具体说说他们的区别 extern都知道 是指该函数在整个工程中可见 而static是指只在当前文件
  • STL : vector 矢量容器

    目录 Vector Capacity Elements access Modifiers Allocator Non member Notice overloads Template specializations Vector inclu
  • 业务流程图怎么画?3步+8张案例,5分钟教你快速上手!

    业务流程图能很好地帮助我们梳理业务 高效表达需求 尤其是产品经理在梳理业务时 经常会用到业务流程图 业务流程图会在产品经理画原型图前 帮助梳理产品业务流程 避免做无用功 今天从业务历程图的基本介绍 常用场景和绘制方法三方面介绍 让大家对业务
  • C11头文件声明了创建和管理线程,信号,条件变量的函数

    作者Danny Kalev 是通过以色列系统分析师协会认证的系统分析师 并且是专攻C 的软件工程师 Kalev 写了多本C 的书籍 同时给不同的软件开发者站点投搞C 文章 他是C 标准委员会的成员 还获得了通用语言学的硕士学位 原始鏈接 h
  • TypeError: can only concatenate list (not "str") to list

    类型错误 只能将list类型和list类型联系起来 而不是str类型 出现上述类型错误 判断一下需要连接的两个变量的类型 如果是将str类型加入list用append添加 如果是移除用pop或remove
  • Ubuntu 10.10下安装TFTP的步骤 tftp-hpa版本

    背景 由于想要在tq2440板子上用tftp下载kernel 所以要在自己的PC机的Ubuntu 10 10上安装tftp服务 所以就去网上找了些教程 但是很悲剧 按照那些教程去操作 结果还都是无法正常运行tftp服务 最后还是从一个外国人
  • 自己动手写CSDN博客提取器,提取文件保存支持PDF、doc、txt三种格式

    转载自 http blog csdn net w397090770 article details 7760907 下载地址http download csdn net detail w397090770 4438566 不需要积分 下面有
  • npm配置及.npmrc文件

    一 npm配置 1 npm cli 提供了npm config 命令进行npm相关配置 通过npm config ls l 可查看npm的所有配置 包括默认配置 2 npm config set 进行配置项修改 使用命令配置后会把配置文件中
  • POJ - 1129 Channel Allocation(染色问题)

    题意 AC代码 When a radio station is broadcasting over a very large area repeaters are used to retransmit the signal so that