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

分析:结点数最多为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. git 管理多个私钥

    .ssh/config文件: host imspring hostname 182.92.153.2 IdentityFile ~/.ssh/id_rsa port 22

  2. 编写一条sql命令,sql删除没有中文的表

    删除包含中文的 和不饱和中文的字段 SHOW create table pages; drop table if exists `film`; CREATE TABLE `film` ( `id` i ...

  3. hadoop伪分布式安装

    hadoop的伪分布安装:一台实体机或虚拟机的安装. 环境:Windows7.VMWare.CentOS 1.1 设置ip地址 说明:在CentOS中的网络的类型: 仅主机模式:虚拟机在Windows ...

  4. Mysql命令-以NULL做where条件过滤时应该写 IS NULL;

    以NULL做where条件过滤时应该写 IS NULL;SELECT * FROM pet WHERE death IS NULL; SELECT * FROM pet WHERE death IS ...

  5. zf-关于SYS_User表type的分类

    type=1 表示管理员 type=2 表示领导 type=3 表示非领导

  6. 转: window中使用PSFTP/WinSCP实现SFTP上传下载

    sftp 服务器:  dbmonitor 1.sftp属于交互式的,所以你得缓存下命令#!/bin/shsftp -o Port=3322 root@172.16.1.21:/opt << ...

  7. centos 7.1搭建docker本地私有仓库返回500错误

    之前有一篇写到在ubuntu14.04系统上安装私有仓库,遇到了两个问题,本次在centos7上遇到了另外一个问题. 安装完仓库并运行registry镜像之后发现push和pull操作都会返回一个50 ...

  8. VMware NAT端口映射外网访问虚拟机linux

    本文目的: 一. SSH连接 二. 访问HTTP VMware Workstation提供了两种虚拟机上网方式,一种bridge,一种NAT,bridge可以获得公网地址,而NAT只能是内网地址了. ...

  9. git@osc使用教程

    http://my.oschina.net/openswc/blog/142321 Git初体验 http://my.oschina.net/dxqr/blog/134811 网友整理的git@osc ...

  10. python之路:进阶篇 内置函数

     li = [11, 22, 33] news = map(  li = [100, 2200, 3300] news = map(  [13, 24, 35] [11, 11, 11] [22, 4 ...