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 ...
随机推荐
- 使用JavaCV/OpenCV抓取并存储摄像头图像
http://blog.csdn.net/ljsspace/article/details/6702178 分类: 图形图像(3) 版权声明:本文为博主原创文章,未经博主允许不得转载. 本程序通过 ...
- jQuery两种扩展插件的方式
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- hdu_5179_beautiful number(数位DP)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5179 题意:给你一个范围,问你漂亮的数有多少个,漂亮的数的定义为 数位高的比数位低的大,并且 数位高的 ...
- Delphi MaskEdit用法(转)
源:http://www.cnblogs.com/zhangzhifeng/archive/2011/10/12/2208640.html MaskEdit是用来建立编辑框的,但它与Edit编辑框可以 ...
- Diamond Collector
Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining ...
- Python3基础 定义无参数无返回值函数 调用会输出hello world的函数
镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...
- CultureInfo中重要的InvariantCulture
CultureInfo简述 CultureInfo类位于System.Globalization命名空间内,这个类和这个命名空间许多人都不了解也认为不需要太多了解,实际上,你写的程序中会经常间接得使用 ...
- Fragmen和Activity之间的通信--接口和实现的分离(转)
Fragmen和Activity之间的通信--接口和实现的分离(转) 分类: Android平台 在平板的开发过程中通常都会采用多个Fragment的实现方式,通常有一个为list的Fragm ...
- php中print_r 和var_dump 打印变量的区别。
<?php $arr = array(true); var_dump($arr); echo "<br/>"; print_r($arr); 结果如下: 说明 p ...
- Blog`s CSS
#div_digg { position: fixed; bottom: 10px; width: 50px; right: 50px; filter: alpha(opacity=20); opac ...