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

【题意】

在这里输入题意

【题解】

暴力做就好。
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. Python正则表达式初识(八)

    继续分享Python正则表达式的基础知识,今天给大家分享的特殊字符是“\w”和“\W”,具体的教程如下. 1.“\w”代表的意思是该字符为任意字符,但是和特殊字符“.”的意思不同.“\w”代表的字符主 ...

  2. HRBUST 1819 石子合并问题--圆形版

    石子合并问题--圆形版 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ...

  3. hdu 5073 Galaxy(2014 鞍山现场赛)

    Galaxy                                                                   Time Limit: 2000/1000 MS (J ...

  4. 《SAS编程与数据挖掘商业案例》学习笔记之十六

    <SAS编程与数据挖掘商业案例>学习笔记,本次重点:sas宏变量 内容包含:宏变量.宏函数.宏參数.通配函数.字符函数.计算函数.引用函数.宏语句.宏应用 1.宏触发器: %name-to ...

  5. Python下opencv使用笔记(一)(图像简单读取、显示与储存)

    写在之前 从去年開始关注python这个软件,途中间间断断看与学过一些关于python的东西.感觉python确实是一个简单优美.easy上手的脚本编程语言,众多的第三方库使得python异常的强大. ...

  6. 智课雅思词汇---三、aud和auto和bene是什么意思

    智课雅思词汇---三.aud和auto和bene是什么意思 一.总结 一句话总结:aud:听 auto:自己,self bene:good,well 1.anthropo是什么意思? anthropo ...

  7. css中margin上下外边距重叠问题

    css的盒子模型里是这样规定两个对象之间的距离的:对象之间的间距是由两个对象的盒子模型的最终计算值得出来的,也就是说两个对象之间的间距就是两个对象的距离,但是当遇到两个对象一个有下外边距margin, ...

  8. command---调用指定的指令并执行

    command命令调用指定的指令并执行,命令执行时不查询shell函数.command命令只能够执行shell内部的命令. 语法 command(参数) 参数 指令:需要调用的指令及参数. 实例 使用 ...

  9. 深入具体解释SQL中的Null

    NULL 在计算机和编程世界中表示的是未知,不确定.尽管中文翻译为 "空", 但此空(null)非彼空(empty). Null表示的是一种未知状态.未来状态,比方小明兜里有多少钱 ...

  10. 高速入手ITOO导入-改进导入.xlsx格式

    这两天一直在研究师哥的导入,在他的基础上进行了一些改进.这次的改进就是能够导入还有一种格式.xlsx格式的.经过几番调试和看师哥写的底层代码最终知道哪里的问题了. workbook = new HSS ...