【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

暴力做就好。
O(8!*26^2)

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
#include <bits/stdc++.h>
using namespace std; const int N = 300; string s;
bool bo[N][N],ex[N];
int A[N],pos[N];
vector <int> v;
int n; int main(){
#ifdef LOCAL_DEFINE
freopen("F:\\c++source\\rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
while (getline(cin,s)){
if (s[0]=='#') break;
memset(bo,0,sizeof bo);
memset(ex,0,sizeof ex);
int len = s.size();
for (int i = 0;i < len;i++)
if (s[i]==';')
s[i] = ' ';
stringstream ss(s);
while (ss>>s){
int len = s.size();
ex[s[0]] = true;
for (int i = 2;i < len;i++){
bo[s[0]][s[i]] = true;
bo[s[i]][s[0]] = true;
ex[s[i]] = true;
}
}
n = 0;
for (int i = 'A';i <='Z';i++)
if (ex[i]){
A[++n] = i;
}
v.resize(n+1);
int ans = 1000;
do{
for (int i = 1;i <= n;i++) pos[A[i]] = i;
int temp = 0;
for (int x = 'A';x<='Z';x++)
for (int y = 'A';y <= 'Z';y++)
if (bo[x][y]==true){
temp = max(temp,abs(pos[x]-pos[y]));
}
if (temp < ans ){
for (int i = 1;i <= n;i++) v[i] = A[i];
ans = temp;
}
}while (next_permutation(A+1,A+1+n)); for (int i = 1;i <= n;i++){
cout << (char)v[i]<<' ';
}
cout <<"-> "<< ans << endl;
}
return 0;
}

【例题 7-6 UVA - 140】Bandwidth的更多相关文章

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

  2. UVa 140 Bandwidth【枚举排列】

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

  3. UVA 140 Bandwidth

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

  4. UVA - 140 Bandwidth(带宽)(全排列)

    题意:给定图,求是带宽最小的结点排列. 分析:结点数最多为8,全排列即可.顶点范围是A~Z. #pragma comment(linker, "/STACK:102400000, 10240 ...

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

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

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

  7. UVa 140 (枚举排列) Bandwidth

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

  8. UVA 140 (13.07.29)

     Bandwidth  Given a graph (V,E) where V is a set of nodes and E is a set of arcsin VxV, and anorderi ...

  9. uva 104 Bandwidth

    题意: 给一个图, 将其节点以任一序列排列. 1)计算每个节点距离相邻节点的最大距离 dis[i] 2)计算出当前序列中, 所有节点的dis[i], 并求出最大的dis[i] : max_dis 求最 ...

随机推荐

  1. JS的解析与执行过程—全局预处理阶段之命名冲突的处理策略

    有如下代码: <body> <script> alert(f); function f() { console.log("fff"); } var f = ...

  2. c++中六种构造函数的实现以及9中情况下,构造函数的调用过程

    六种构造函数的实现代码例如以下: #include<iostream> using namespace std; //c++中六种默认的构造函数 class Test { public: ...

  3. Objective-C method及相关方法分析

    ## Objective-C method及相关方法分析 转载请注名出处 [http://blog.csdn.net/uxyheaven](http://blog.csdn.net/uxyheaven ...

  4. js---03属性操作

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  5. vim 解决tags递归查询问题

    今天在vim下配置了两个插件,分别是exuberant-ctags 跟cscope.这两个插件主要是用来实现类.方法查询跟跳转.至于它们如何安装跟使用,网上教程一大堆,我也是按着别的大神教程一步步来的 ...

  6. Linux下安装zip解压功能

    liunx服务器上默认没有安装zip命令,所以使用时需安装:apt-get install zip 或  yum install zip linux安装unzip命令:apt-get install ...

  7. EF搭建数据库

    http://blog.csdn.net/mss359681091/article/details/52135867http://blog.csdn.net/x_craft/article/detai ...

  8. 【hdu 6038】Function

    [Link]:http://codeforces.com/contest/834/problem/C [Description] 给你两个排列a和b; a排列的长度为n,b排列的长度为m; a∈[0. ...

  9. ArcGIS “Error HRESULT E_FAIL has been returned from a call to a COM component.” 异常的解决

    错误提示内容: {System.Runtime.InteropServices.COMException (0x80004005): Error HRESULT E_FAIL has been ret ...

  10. 关于XAMPP安装后APACH无法启动的问题

    Xampp的获得和安装都十分简单,你仅仅要到下面网址: http://www.apachefriends.org/zh_cn/xampp.html 下载xampp就可以.我安装的是windows版本号 ...