【例题 7-6 UVA - 140】Bandwidth
【链接】 我是链接,点我呀:)
【题意】
在这里输入题意
【题解】
暴力做就好。
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的更多相关文章
- 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【枚举排列】
题意:给出n个节点的图,和一个节点的排列,定义节点i的带宽b[i]为i和其相邻节点在排列中的最远的距离,所有的b[i]的最大值为这个图的带宽,给一个图,求出带宽最小的节点排列 看的紫书,紫书上说得很详 ...
- UVA 140 Bandwidth
题意: 给出一个n个节点的图G,和一个节点的排列,定义节点i的带宽为i和相邻节点在排列中的最远距离,而所有带宽的最大值就是图的带宽,求让图的带宽最小的排列. 分析: 列出所有可能的排列,记录当前找到的 ...
- UVA - 140 Bandwidth(带宽)(全排列)
题意:给定图,求是带宽最小的结点排列. 分析:结点数最多为8,全排列即可.顶点范围是A~Z. #pragma comment(linker, "/STACK:102400000, 10240 ...
- UVA 140 Bandwidth (dfs 剪枝 映射)
题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...
- 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
题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. STL里的next_permutation函数真是好用. 比较蛋疼的就是题目的输入了.. ...
- 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 ...
- uva 104 Bandwidth
题意: 给一个图, 将其节点以任一序列排列. 1)计算每个节点距离相邻节点的最大距离 dis[i] 2)计算出当前序列中, 所有节点的dis[i], 并求出最大的dis[i] : max_dis 求最 ...
随机推荐
- jquery点击弹框外层关闭弹框
$(document).bind("click",function(e){ if($( e.target ).closest(".game-cont ...
- WPF 支持的多线程 UI 并不是线程安全的
原文:WPF 支持的多线程 UI 并不是线程安全的 版权声明:本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可.欢迎转载.使用.重新发布,但务必保留文章署名吕毅(包含链 ...
- Linux学习总结(2)——linux常用命令大全
玩过Linux的人都会知道,Linux中的命令的确是非常多,但是玩过Linux的人也从来不会因为Linux的命令如此之多而烦恼,因为我们只需要掌握我们最常用的命令就可以了.当然你也可以在使用时去找一下 ...
- 解决WIN7远程登录提示无法保存凭据的问题
事由:今天到公司,想起手上还有点小东西没有改动完,就打算连上server进行小改动.结果发现昨天还能好好的远程连接server的WIN7,今天突然间不能远程登录了~ 无奈~悲催~ 我仅仅能猜是不是有什 ...
- SQL两表之间:依据一个表的字段更新还有一个表的字段
1. 写法轻松.更新效率高: update table1 set field1=table2.field1, field2=table2.field2 from table2 where table1 ...
- 思科2960trunk vlan配置及路由IP配置
en conf t vlan id end conf t inter rang gi 0/0/1-x switchport access vlan id no shutdown exit (confi ...
- occActiveX - ActiveX with OpenCASCADE
occActiveX - ActiveX with OpenCASCADE eryar@163.com Abstract. OpenCASCADE ActiveX wrapper for VB, C# ...
- 小白算法之路-非确定性多项式(non-deterministic polynomial,缩写NP)
前端小白的算法之路 时隔多日终于解决了埋在心头的一道难题,霎时云开雾散,今天把一路而来碰到的疑惑和心得都记录下来,也算是开启了自己探索算法的大门. 问题背景 曾经有一个年少轻狂的职场小白,在前端圈 ...
- js中常用的对象—String的属性和方法
今天说一下,js中常用的内置对象——String对象它有以下几个常用的属性:lengthprototype 有以下几个常用的方法:parseInt()转换为数字parseFloat()转换为数字,支持 ...
- assert增强宏的实现
作者:朱金灿 来源:http://blog.csdn.net/clever101 标准c的assert宏和MFC的ASSERT宏都不支持输出太多的信息.今天实现了一个assert增强宏,可以输出更多的 ...