UVa 140 - BandWidth 解题报告(暴力)
来源:互联网 发布:非关系型数据库 编辑:程序博客网 时间:2024/05/14 16:08
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 thebandwidth 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:
This can be ordered in many ways, two of which are illustrated below:
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
解题报告:枚举所有排列,计算出最小值。没啥好说的。代码如下:
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <iomanip>using namespace std;#define ff(i, n) for(int i=0;i<(n);i++)#define fff(i, n, m) for(int i=(n);i<=(m);i++)#define dff(i, n, m) for(int i=(n);i>=(m);i--)#define bit(n) (1LL<<(n))typedef long long LL;typedef unsigned long long ULL;void work();int main(){#ifdef ACM freopen("in.txt", "r", stdin);#endif // ACM work();}/***************************************************/char str[10];char tmp[10];bool has[100];bool line[100][100];void work(){ char ch; while(ch = getchar(), ch != '#') { memset(has, 0, sizeof(has)); memset(line, 0, sizeof(line)); int status = 0; char cur; do { if(ch == ':') status = 1; else if(ch == ';') status = 0; else if(status == 0) cur = ch, has[ch] = true; else if(status == 1) line[cur][ch] = line[ch][cur] = true, has[ch] = true; } while(ch = getchar(), ch != '\n'); int len = 0; fff(i, 'A', 'Z') if(has[i]) str[len++] = i; int ans = 10; do { int maxD = 0; ff(i, len) ff(j, len) if(line[str[i]][str[j]]) maxD = max(maxD, abs(i-j)); if(maxD < ans) { ans = maxD; memcpy(tmp, str, sizeof(str)); } } while(next_permutation(str, str+len)); ff(i, len) printf("%c ", tmp[i]); printf("-> %d\n", ans); }}
- UVa 140 - BandWidth 解题报告(暴力)
- UVa 140 - BandWidth (暴力)
- UVa 140:Bandwidth(暴力)
- UVA 140——Bandwidth(暴力)
- UVA 140 Bandwidth 暴力模拟
- UVa 669 - Defragment 解题报告(暴力)
- UVa 165 - Stamps 解题报告(暴力)
- UVa 225 - Golygons 解题报告(暴力)
- uva 140 Bandwidth (全排列+暴力枚举)
- UVA 140 带宽 Bandwidth (暴力枚举+剪枝)
- UVA 140 - Bandwidth 暴力 全排列 回溯
- UVa 10317 Equating Equations 解题报告(暴力)
- UVa 1533 Moving Pegs 解题报告(暴力+码力)
- UVa 110 Meta-Loopless Sorts 解题报告(暴力)
- UVa 120 - Stacks of Flapjacks 解题报告(暴力)
- UVa 269 Counting Patterns 解题报告(暴力)
- UVa 387 - A Puzzling Problem 解题报告(暴力)
- 【Jason's_ACM_解题报告】Bandwidth
- 机会只看到房价多少了罚款时间到了数字机顶盒
- POJ The Triangle
- 通过扩展 CWebUser 增加信息到 Yii::app()->user
- mysql修改root密码
- 圆角和圆形ImageView
- UVa 140 - BandWidth 解题报告(暴力)
- Java冒泡排序算法
- C语言编译四则运算
- 加密数
- JDBC数据库通用DAO
- PackageManager使用
- hdoj.2003 求绝对值 20140721
- 手机内存卡格式化文件怎么恢复
- HDU1102 Constructing Roads 【最小生成树Prim】