Channel Allocation
来源:互联网 发布:程序员之死的文化深意 编辑:程序博客网 时间:2024/05/21 04:16
Channel Allocation
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 20000/10000K (Java/Other)
Total Submission(s) : 36 Accepted Submission(s) : 17
Problem Description
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.
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. <br> <br>Following the number of repeaters is a list of adjacency relationships. Each line has the form: <br> <br>A:BCDH <br> <br>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 <br> <br>A: <br> <br>The repeaters are listed in alphabetical order. <br> <br>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. <br>
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
2A:B:4A:BCB:ACDC:ABDD:BC4A:BCDB:ACDC:ABDD:ABC0
Sample Output
1 channel needed.3 channels needed.4 channels needed.
这是一个我给单词绕到了的题,英文这个东西真是博大精深,一词多义啊。读题的时候,什么广播、中继器的,都不认识,查单词出来的,但是另一个词 channel (咋一看很像香奈儿啊,当然我也不会傻到以为这是香奈儿的意思),查出来词义是这个样子的: n. 通道;频道;海峡 vt. 引导,开导;形成河道 我一看通道,以为这是电缆线一类的意思,毕竟传输信号嘛,那就是相邻的不能接入同一个通道里面,但是他也没说怎么接通道啊,然后翻来覆去想不到题意是个啥意思,实在没办法去题解看题意,人家的解释是:频道。哪里接过来意思就像是给每个中继器染色,相邻的不能同一个颜色,这样就明白的多了。明白了题意就好做的多了,深搜回溯,求最小值。输出的地方也要注意啊,名词单复数加不加 -s的看不看的到!!!
代码如下:
#include<iostream>#include<cstring>#include<stdio.h>using namespace std;int mapp[30][30];int vis[30];//点 i 颜色int n,minn,flag;int ok(int x,int c)//判断 x 是否能 染 c{ for(int i=1;i<=n;i++) { if(mapp[x][i]==1 && vis[i]==c) return 0; } return 1;}void ioan(int x,int color){ if(x>n) { flag=1; if(minn>color) minn=color; return ; } //int f=0; for(int i=1;i<=color;i++)//在 x 上染色 { if(ok(x,i)) { //f=1; vis[x]=i; ioan(x+1,color); if(flag==1) return ; vis[x]=0; } } { vis[x]=color+1; ioan(x+1,color+1); }}int main(){ //freopen("D:\\aaa.txt","r",stdin); string s; int l,x,y; while(cin>>n&&n) { minn=9999; flag=0; memset(mapp,0,sizeof(mapp)); memset(vis,0,sizeof(vis)); for(int i=0;i<n;i++) { cin>>s; l=s.size(); x=s[0]-'A'+1; for(int i=2;i<l;i++) { y=s[i]-'A'+1; mapp[x][y]=1; mapp[y][x]=1; } } ioan(1,1); if(minn==1) cout<<minn<<" channel needed."<<endl; if(minn!=1) cout<<minn<<" channels needed."<<endl; } return 0;}
阅读全文
0 0
- Channel Allocation
- Channel Allocation
- Channel Allocation
- JOJ 1003 Channel Allocation
- JOJ 1003: Channel Allocation
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- poj 1129 Channel Allocation
- poj 1129Channel Allocation
- poj 1129 Channel Allocation
- ZOJ 1084 Channel Allocation
- N - Channel Allocation
- (难)Channel Allocation(P1129)
- poj_1129 Channel Allocation
- POJ1129—Channel Allocation
- poj 1129 Channel Allocation
- POJ 1129 Channel Allocation
- POJ 1129 Channel Allocation
- mybatis jdbc Type 与java Type对照表 以及ResultMap元素讲解
- iOS 开发 Guideline 4.3
- SQLyog导出csv文件内容都在一列的解决办法
- 修复:pip 'module' object has no attribute '_handlerList'
- eclipse使用ctrl+鼠标左键进入代码后,原路返回
- Channel Allocation
- ps命令
- 【MySQL系列--优化2】——外连接简化
- MySQL索引
- 38. Count and Say
- 文档流下的css定位 常见问题解决汇总
- 【R语言】问题处理
- editText设置输入最大值(不是长度)
- zip map