UVA - 140 Bandwidth(带宽)(全排列)
题意:给定图,求是带宽最小的结点排列。
分析:结点数最多为8,全排列即可。顶点范围是A~Z。
#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
typedef long long ll;
typedef unsigned long long llu;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {, , -, , -, -, , };
const int dc[] = {-, , , , -, , -, };
const int MOD = 1e9 + ;
const double pi = acos(-1.0);
const double eps = 1e-;
const int MAXN = + ;
const int MAXT = + ;
using namespace std;
char s[MAXN];
set<int> node[];
vector<int> v;
int t[];
void init(){
for(int i = ; i < ; ++i){
node[i].clear();
}
v.clear();
memset(t, , sizeof t);
int len = strlen(s);
for(int i = ; i < len; ++i){
if(s[i] == ':'){
int tmp = s[i - ] - 'A';
while(){
++i;
if(i == len) break;
if(s[i] == ';') break;
node[tmp].insert(s[i] - 'A');
node[s[i] - 'A'].insert(tmp);
}
}
}
}
int main(){
while(scanf("%s", s) == ){
if(s[] == '#') return ;
init();
for(int i = ; i < ; ++i){
if(node[i].size()){
v.push_back(i);
}
}
int len = v.size();
int ans = INT_M_INF;
do{
int tmp = ;
for(int i = ; i < len; ++i){
for(int j = ; j < i; ++j){
if(node[v[i]].count(v[j])){
tmp = max(tmp, i - j);
}
}
}
if(tmp < ans){
ans = tmp;
for(int i = ; i < len; ++i){
t[i] = v[i];
}
}
}while(next_permutation(v.begin(), v.end()));
for(int i = ; i < len; ++i){
printf("%c ", 'A' + t[i]);
}
printf("-> %d\n", ans);
}
return ;
}
UVA - 140 Bandwidth(带宽)(全排列)的更多相关文章
- UVa OJ 140 - Bandwidth (带宽)
Time limit: 3.000 seconds限时3.000秒 Problem问题 Given a graph (V,E) where V is a set of nodes and E is a ...
- uva 140 bandwidth (好题) ——yhx
Bandwidth Given a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an orde ...
- UVA 140 Bandwidth (dfs 剪枝 映射)
题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...
- UVa 140 Bandwidth【枚举排列】
题意:给出n个节点的图,和一个节点的排列,定义节点i的带宽b[i]为i和其相邻节点在排列中的最远的距离,所有的b[i]的最大值为这个图的带宽,给一个图,求出带宽最小的节点排列 看的紫书,紫书上说得很详 ...
- UVA 140 Bandwidth
题意: 给出一个n个节点的图G,和一个节点的排列,定义节点i的带宽为i和相邻节点在排列中的最远距离,而所有带宽的最大值就是图的带宽,求让图的带宽最小的排列. 分析: 列出所有可能的排列,记录当前找到的 ...
- UVA 140 Brandwidth 带宽 (dfs回溯)
看到next_permutation好像也能过╮(╯▽╰)╭ 这题学习点: 1.建图做映射 2.通过定序枚举保证字典序最小 3.strtok,sscanf,strchr等函数又复习了一遍,尽管程序中没 ...
- UVa 140 (枚举排列) Bandwidth
题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...
- UVa 140 带宽
题意:给出一个n个结点的图G和一个结点的排列,定义结点的带宽为i和相邻结点在排列中的最远距离,求出让带宽最小的结点排列. 思路:用STL的next_permutation来做确实是很方便,适当剪枝一下 ...
- 【例题 7-6 UVA - 140】Bandwidth
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 暴力做就好. O(8!*26^2) [代码] /* 1.Shoud it use long long ? 2.Have you ev ...
随机推荐
- css脱离文档流
作者:张秋怡链接:http://www.zhihu.com/question/24529373/answer/29135021来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...
- 转 区别 getChildFragmentManager getSupportFragmentManager
The definition of getChildFragmentManager() is: Return a private FragmentManager for placing and man ...
- FACE++学习二、获得face属性
http://blog.csdn.net/lyq8479/article/details/17362685 为了防止网页丢失还是自己保存一份安全一点 人脸检测API介绍 在Face++网站的“API文 ...
- 风格一致的backItem在项目中怎样设置
在相应的navigationController中重写- (void)pushViewController:(UIViewController *)viewController animated:(B ...
- hrbustoj 1985(进制转换函数)
这个水题当然没有好说的,主要是介绍一个很牛掰的函数 strtol(b,NULL,k)这个函数可以直接把字符串b转化为k进制的数 #include<stdio.h> #include< ...
- 使用Three.js渲染Sketchup导出的dae
打算做个轮盘游戏,直接上3D吧. 第一步:制作模型 3DMax和Maya下载和破解比较麻烦, 就用之前的Sketchup来试试吧. 最后效果图: 俯视图 仰视图 制作步骤: 1 先画一个圆 2 从圆心 ...
- c# dev控件 gridcontrol 数据跟随鼠标滚轮滚动也可以编辑
在绑定书到gridControl后经常发现: 如果你设置了 this.gridView3.OptionsBehavior.Editable = false; 那数据可以跟随滚轮滚动,但如果你要复制某个 ...
- 【HighCharts系列教程】四、颜色属性——colors
一.Colors属性说明 配置Colors,可以自定义数据列的颜色. 默认下colors就包含一系列颜色,在个性化或需要调整颜色的顺序下,我们可以配置该属性. 二.colors属性详解 Colors属 ...
- 考分鄙视(exam)
考分鄙视(exam) 题目描述 Whence这个学期考了n次试,每一次都有一个0-20000之间的整数分数.Whence本来的状态应该是每一次考试都比前一次多一分(除第一次),但由于他很不稳定,偏差可 ...
- gcd timer
//0.创建队列 dispatch_queue_t queue = dispatch_get_global_queue(, ); NSLog(@"%s",__func__); // ...