uva 140
思路:暴力+剪枝
wa了好多次……数组开小了……!!!
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <algorithm>
- #include <cstdlib>
- #include <stack>
- #include <cctype>
- #include <string>
- #include <malloc.h>
- #include <queue>
- #include <map>
- using namespace std;
- const int INF = 0xffffff;
- const double esp = 10e-;
- const double Pi = * atan(1.0);
- const int Maxn = ;
- const int mod = ;
- const int dr[] = {,,-,,-,,-,};
- const int dc[] = {,,,-,,-,-,};
- //int dir2[8][2] = {{-1,0},{0,-1},{-1,1},{1,-1},{-1,-1},{1,0},{0,1},{1,1}};
- bool graph[Maxn][Maxn];
- int arr[Maxn];
- int n;
- int Min;
- int tot;
- bool visit[Maxn];
- int ans[Maxn];
- int init[Maxn];
- void dfs(int cur){
- if(tot >= Min)
- return;
- if(cur == n){
- Min = min(Min,tot);
- for(int i = ;i < n;i++){
- ans[i] = arr[i];
- }
- return;
- }
- for(int i = ;i < n;i++){
- if(!visit[ init[i] ]){
- visit[init[i]] = ;
- arr[cur] = init[i];
- int tmp = ;
- for(int j = ;j < cur;j++){
- if(graph[ arr[j] ][ init[i] ]){
- int tt = abs(cur - j);
- tmp = max(tmp,tt);
- if(tmp > Min)
- break;
- }
- }
- int tt = tot;
- tot = max(tmp,tot);
- dfs(cur+);
- visit[init[i]] = ;
- tot = tt;
- }
- }
- }
- char str[];
- int main()
- {
- #ifndef ONLINE_JUDGE
- freopen("inpt.txt","r",stdin);
- #endif
- while(scanf("%s",str) != EOF){
- if(str[] == '#')
- break;
- int len = strlen(str);
- n = ;
- memset(graph,,sizeof(graph));
- memset(arr,,sizeof(arr));
- memset(visit,,sizeof(visit));
- for(int i = ;i < len;i++){
- if(str[i] == ' ')
- continue;
- int a = str[i] - 'A';
- if(!arr[a]){
- init[n++] = str[i] - 'A';
- arr[a] = ;
- }
- for(i = i+;str[i] != ';' && i < len;i++){
- if(!isalpha(str[i]))
- continue;
- int b = str[i] - 'A';
- graph[a][b] = ;
- graph[b][a] = ;
- if(!arr[b]){
- init[n++] = str[i] - 'A';
- arr[b] = ;
- }
- }
- }
- Min = INF;
- tot = ;
- sort(init,init+n);
- dfs();
- for(int i = ;i < n;i++){
- printf("%c ",ans[i] + 'A');
- }
- printf("-> %d\n",Min);
- }
- return ;
- }
uva 140的更多相关文章
- 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
题意较复杂,请参见原题=_=|| 没什么好说的,直接枚举每个排列就好了,然后记录最小带宽,以及对应的最佳排列. 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 140 Bandwidth
题意: 给出一个n个节点的图G,和一个节点的排列,定义节点i的带宽为i和相邻节点在排列中的最远距离,而所有带宽的最大值就是图的带宽,求让图的带宽最小的排列. 分析: 列出所有可能的排列,记录当前找到的 ...
- UVA - 140 Bandwidth(带宽)(全排列)
题意:给定图,求是带宽最小的结点排列. 分析:结点数最多为8,全排列即可.顶点范围是A~Z. #pragma comment(linker, "/STACK:102400000, 10240 ...
- UVa 140 带宽
题意:给出一个n个结点的图G和一个结点的排列,定义结点的带宽为i和相邻结点在排列中的最远距离,求出让带宽最小的结点排列. 思路:用STL的next_permutation来做确实是很方便,适当剪枝一下 ...
- UVA 140 Brandwidth 带宽 (dfs回溯)
看到next_permutation好像也能过╮(╯▽╰)╭ 这题学习点: 1.建图做映射 2.通过定序枚举保证字典序最小 3.strtok,sscanf,strchr等函数又复习了一遍,尽管程序中没 ...
- UVA 140 Bandwidth (dfs 剪枝 映射)
题意: 给定一个n个结点的图G和一个结点的排列, 定义结点i的带宽b(i)为i和相邻结点在排列中的最远距离, 所有b(i)的最大值就是这个图的带宽, 给定G, 求让带宽最小的结点排列. 给定的图 n ...
- UVa 140 Bandwidth【枚举排列】
题意:给出n个节点的图,和一个节点的排列,定义节点i的带宽b[i]为i和其相邻节点在排列中的最远的距离,所有的b[i]的最大值为这个图的带宽,给一个图,求出带宽最小的节点排列 看的紫书,紫书上说得很详 ...
随机推荐
- 在Windows下github展示代码
最近大爱Web编程,于是寻找各种代码中,然后就发现了GitHub这个网站,如果你知道Google Code,那么你就知道这个GitHub是做什么的了.不过GitHub主要是用作基于Git的分布式版本管 ...
- 笔记之Cyclone IV第一卷第四章Cyclone IV器件中的嵌入式乘法器
嵌入式乘法器可以配置成一个 18 × 18 乘法器,或者配置成两个 9 × 9 乘法器.对于那些大于18 × 18 的乘法运算 ,Quartus II 软件会将多个嵌入式乘法器模块级联在一起.虽然没有 ...
- ASP.NET Core (一):简介
下一篇:ASP.NET Core(二):入门 英文原版:Introduction to ASP.NET Core 关于ASP.NET Core ASP.NET Core 是一个全新的开源.跨平台框架, ...
- 17.1.1.3 Creating a User for Replication
17.1.1.3 Creating a User for Replication 创建一个用户用于复制: 每个slave 连接到master 使用一个MySQL 用户名和密码, 因此必须有一个user ...
- H面试程序(28):字符串处理转换
//2 字符串处理转换 //问题描述: //在给定字符串中找出单词( “单词”由大写字母和小写字母字符构成, //其他非字母字符视为单词的间隔,如空格.问号.数字等等:另外单个字母不算单词): //找 ...
- oracle scn浅析
1. 系统SCN号 查询系统SCN号的方法: select dbms_flashback.get_system_change_number from dual commit后系统SCN号会增长,但是即 ...
- ACM比赛(第二次A)
ime Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Description There is ...
- java--异常处理总结
[在程序中抛出异常] 在程序中抛出异常,一定要使用关键字throw. throw+异常实例对象. public class Demo2 { public static void main(String ...
- ZOJ 3603字符串操作
解题思路:找到公共子串然后升序输出 坑的地方就在于输入是存在相同字母的 #include <stdio.h> #include <algorithm> #include < ...
- PHP - 接口 - 单一接口
/* * 接口的使用 */ //定义接口 interface IPerosn{ public function eat(); public function water(); } //定义继承自接口的 ...