题意:给定图,求是带宽最小的结点排列。

分析:结点数最多为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(带宽)(全排列)的更多相关文章

  1. 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 ...

  2. 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 ...

  3. UVA 140 Bandwidth (dfs 剪枝 映射)

    题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...

  4. UVa 140 Bandwidth【枚举排列】

    题意:给出n个节点的图,和一个节点的排列,定义节点i的带宽b[i]为i和其相邻节点在排列中的最远的距离,所有的b[i]的最大值为这个图的带宽,给一个图,求出带宽最小的节点排列 看的紫书,紫书上说得很详 ...

  5. UVA 140 Bandwidth

    题意: 给出一个n个节点的图G,和一个节点的排列,定义节点i的带宽为i和相邻节点在排列中的最远距离,而所有带宽的最大值就是图的带宽,求让图的带宽最小的排列. 分析: 列出所有可能的排列,记录当前找到的 ...

  6. UVA 140 Brandwidth 带宽 (dfs回溯)

    看到next_permutation好像也能过╮(╯▽╰)╭ 这题学习点: 1.建图做映射 2.通过定序枚举保证字典序最小 3.strtok,sscanf,strchr等函数又复习了一遍,尽管程序中没 ...

  7. UVa 140 (枚举排列) Bandwidth

    题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...

  8. UVa 140 带宽

    题意:给出一个n个结点的图G和一个结点的排列,定义结点的带宽为i和相邻结点在排列中的最远距离,求出让带宽最小的结点排列. 思路:用STL的next_permutation来做确实是很方便,适当剪枝一下 ...

  9. 【例题 7-6 UVA - 140】Bandwidth

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 暴力做就好. O(8!*26^2) [代码] /* 1.Shoud it use long long ? 2.Have you ev ...

随机推荐

  1. json optString getString

    optString 和 getString 区别.   optString 当接收到的为空时候  不会报错

  2. C#入门经典-第15章Windows 编程

    在使用Windows窗体时,就是使用System.Windows.Forms名称空间. .NET中的大多数控件都派生于System.Windows.Forms.Control类.

  3. 2016大连网络赛 Different GCD Subarray Query

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  4. Struts2.3.16日志(中)

    Result Configuration --Result 配置 当一个操作类方法完成后,它将返回一个字符串.字符串的值是用来选择一个元素的结果.一个操作映射的结果往往会有一组代表不同的可能的结果.一 ...

  5. PAT (Advanced Level) 1063. Set Similarity (25)

    读入之后先排序. 询问的时候可以o(m)效率得到答案. #include<cstdio> #include<cstring> #include<cmath> #in ...

  6. PHP聊天室开源系统workerman-chat

    PHP聊天室开源系统workerman-chat (2015-01-23 09:07:50) 转载▼ http://www.workerman.net/ http://www.workerman.ne ...

  7. learn from 德国老师

    最近在跟踪德国来的一个老师学android,感触比较深的一点就是他对细节的理解,一个源代码他可以从第一行解释到最后一行,知道每一行的意思和用法,这可能就是德国人对细节的追求. 刚才想了一下写代码确实应 ...

  8. JS中判定问题

    今天项目遇到一个很奇怪的问题,具体问题不好说明简化下,有如下一个方法: function editStu(index, rowData) { if (index == "") { ...

  9. C#WinForm中复制、粘贴文本到剪贴板

    //复制: private void button1_Click(object sender, System.EventArgs e) {   if(textBox1.SelectedText != ...

  10. express4.x中路由中间件和挂载路径的关系

    express4.x 中一个路由中间件可以挂载到多个路由上,一个路由也可以绑定多个路由中间件,如: //多个路由匹配一个路由中间件 app.use(['/gre+t', '/hel{2}o'], gr ...