UVA - 140 Bandwidth(全排列枚举)

探讨图论中节点排序的问题,目标是最小化给定图的带宽。通过全排列的方法枚举所有可能的排序,并计算每种排序的带宽,选择最小带宽的排序作为最优解。

 Bandwidth 

Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an ordering on the elements in V, then the bandwidth of a node v is defined as the maximum distance in the ordering between v and any node to which it is connected in the graph. The bandwidth of the ordering is then defined as the maximum of the individual bandwidths. For example, consider the following graph:

picture25

This can be ordered in many ways, two of which are illustrated below:

picture47

For these orderings, the bandwidths of the nodes (in order) are 6, 6, 1, 4, 1, 1, 6, 6 giving an ordering bandwidth of 6, and 5, 3, 1, 4, 3, 5, 1, 4 giving an ordering bandwidth of 5.

Write a program that will find the ordering of a graph that minimises the bandwidth.

Input

Input will consist of a series of graphs. Each graph will appear on a line by itself. The entire file will be terminated by a line consisting of a single #. For each graph, the input will consist of a series of records separated by `;'. Each record will consist of a node name (a single upper case character in the the range `A' to `Z'), followed by a `:' and at least one of its neighbours. The graph will contain no more than 8 nodes.

Output

Output will consist of one line for each graph, listing the ordering of the nodes followed by an arrow (->) and the bandwidth for that ordering. All items must be separated from their neighbours by exactly one space. If more than one ordering produces the same bandwidth, then choose the smallest in lexicographic ordering, that is the one that would appear first in an alphabetic listing.

Sample input

A:FB;B:GC;D:GC;F:AGH;E:HD
#

Sample output

A B C F G D H E -> 3


题目大意:
给定一个图(V,E),其中V为顶点的集合,E为边的集合,属于VxV。给定V中元素的一种排序,那么顶点v的带宽定义如下:在当前给定的排序中,与v距离最远的且与v有边相连的顶点与v的距离。给定排序的带宽定义为各顶点带宽的最大值。写一个程序,找出该图的一种排序使其带宽最小。


解析:直接用全排列枚举出所有的可能,分别计算带宽,然后选取最小的一种方案。

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 30;
int edge[N][N];
bool vis[N];
int arr[N];
int n;

void init(char str[]) {
	memset(edge,0,sizeof(edge));
	memset(vis,0,sizeof(vis));
	int u,v;
	int len = strlen(str);
	for(int i = 0; i < len;) {
		if(str[i] >= 'A' && str[i] <= 'Z') {
			u = str[i] - 'A';
			vis[u] = true;
			i++;
		}else if(str[i] == ':') {
			while(str[i] != ';' && str[i] != '\0') {
				if( str[i] >= 'A' && str[i] <= 'Z') {
					v= str[i] - 'A';
					vis[v] = true;
					edge[u][v] = edge[v][u] = 1;
				}
				i++;
			}
			i++;
		}
	}
	n = 0; //保存节点个数
	for(int i = 0; i < N; i++) {
		if( vis[i]) {
			arr[n++] = i;
		}
	}
}

int solve() {
	int u,v;
	int d,maxd,Max;
	Max = -INF;
	for(int i = 0; i < n; i++) {
		u = arr[i];
		maxd = -INF;
		for(int j = i+1; j < n; j++) {
			v = arr[j];
			if(edge[u][v]) {
				d = j - i;	
			}
			maxd = max(d,maxd);
		}
		Max = max(Max,maxd);
	}
	return Max;
}
int main() {
	char str[N];
	char tmp[N];
	while(scanf("%s",str) != EOF) {
		if( str[0] == '#') {
			break;
		}
		init(str);
		sort(arr,arr+n);
		
		int Min = INF,sum;
		do{
			sum = solve();
			if( Min > sum) {
				Min = sum;
				for(int i = 0; i < n; i++) {
					tmp[i] = arr[i] + 'A';
				}
			}
		}while(next_permutation(arr,arr+n));
		for(int i = 0; i < n; i++) {
			printf("%c ",tmp[i]);
		}
		printf("-> %d\n",Min);
	}
	return 0;
}

### PLL 闭合回路带宽解释 在通信系统和电子工程领域,PLL(Phase-Locked Loop, 锁相环)是一种用于同步信号频率和相位的重要电路。PLL 的性能很大程度上取决于其闭合回路带宽 (Closed-Loop Bandwidth),这一参数决定了系统的响应速度以及对外界干扰的抑制能力。 #### 定义与作用 闭合回路带宽是指当输入信号发生变化时,PLL 能够跟踪该变化的最大频率范围。在这个范围内,PLL 可以有效地调整自身的输出来匹配输入的变化。如果超过这个范围,则可能导致失锁现象发生[^1]。 对于大多数应用而言,合适的闭环带宽设置可以提高锁定时间并减少抖动;然而过高的值可能会降低噪声抑制效果,并使系统变得不稳定。因此,在设计过程中需要权衡这些因素以找到最佳点。 #### 计算方法 计算 PLL 的闭合回路带宽通常涉及到以下几个方面: - **开环增益**:这是指在整个控制路径中的总放大倍数,包括鉴频器/鉴相器、滤波器及压控振荡器(VCO)等组件的影响。 - **反馈系数**:即分频比 N 或者其他形式的比例因子,它影响着实际工作状态下 VCO 输出相对于参考输入之间的关系。 通过分析上述两个要素以及其他可能存在的补偿网络特性,可以利用传递函数理论得出具体的表达式来进行定量评估。一般情况下会采用 Bode 图或其他类似的工具辅助完成这项任务。 ```matlab % MATLAB code to plot a simple example of open loop gain vs frequency response. f = logspace(-2, 3); % Frequency vector from 0.01Hz to 1kHz on logarithmic scale G_open_loop = @(w)(1 ./ (1 + j*w*0.01)); % Example transfer function for demonstration purposes only. figure; bodemag(G_open_loop(f), f); title('Open Loop Gain Magnitude Response'); xlabel('Frequency [rad/s]'); ylabel('Magnitude [dB]'); grid on; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值