UVa 124 Following Orders
// Following Orders
// UVa ID: 124
// Verdict: Accepted
// Submission Date: 2015-11-27
// UVa Run Time: 0.000s
//
// 版权所有(C)2015,邱秋。metaphysis # yeah dot net#include <iostream>
#include <cstring>
#include <sstream>
#include <algorithm>using namespace std;#define MAXN 20bool visited[MAXN];
int nChar, value[2 * MAXN], nLimit;
char output[MAXN], input[MAXN], limit[MAXN][2];void print()
{for (int i = 0; i < nChar; i++)cout << output[i];cout << endl;
}bool isValid()
{for (int i = 0; i < nLimit; i++)if (value[limit[i][0] - 'a'] >= 0 &&value[limit[i][1] - 'a'] >= 0 &&value[limit[i][0] - 'a'] > value[limit[i][1] - 'a'])return false;return true;
}void lexicographical(int current)
{if (current >= 2 && !isValid())return;if (current == nChar){print();return;}for (int i = 0; i < nChar; i++)if (!visited[i]){visited[i] = true;output[current] = input[i];value[input[i] - 'a'] = current;lexicographical(current + 1);value[input[i] - 'a'] = -1;visited[i] = false;}
}bool cmp(char a, char b)
{return a < b;
}int main(int ac, char *av[])
{string line;int cases = 0;while (getline(cin, line), line.length() > 0){// 输出间隔空行。if (cases > 0)cout << endl;// 读取字符,初始化相关变量。istringstream first(line);nChar = 0;while (first >> input[nChar]){output[nChar] = 0;visited[nChar] = false;nChar++;}for (int i = 0; i < 2 * MAXN; i++)value[i] = -1;sort(input, input + nChar, cmp);// 读取限制。nLimit = 0;getline(cin, line);istringstream next(line);while (next >> limit[nLimit][0])next >> limit[nLimit++][1];// 使用回溯生成字典序排列然后检查是否符合限制条件。lexicographical(0);cases++;}return 0;
}
UVa 124 Following Orders相关推荐
- UVa Online Judge 工具網站
UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...
- uva 10256 The Great Divide (Convex Hull, Simple)
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=sh ...
- POJ 3525/UVA 1396 Most Distant Point from the Sea(二分+半平面交)
Description The main land of Japan called Honshu is an island surrounded by the sea. In such an isla ...
- UVa 11027 - Palindromic Permutation 回文串,组合加搜索
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=s ...
- uva 11275 3D Triangles (3D-Geometry)
uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...
- UVa 207 - PGA Tour Prize Money
时间限制:3.000秒 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&catego ...
- UVa 1471 Defense Lines - 线段树 - 离散化
题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...
- Ananagrams(sort+map) UVA - 156 统计字谜
Ananagrams(sort+map) UVA - 156 统计字谜 Most crossword puzzle fans are used to anagrams - groups of word ...
- UVa 109 - SCUD Busters(凸包计算)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- Candy UVA 1639 (数学期望)
Candy UVA 1639 (数学期望) 有两个盒子各有n颗糖(n<=2*105),从两个盒子取糖的概率为p和1-p,直到一个盒子没糖,求另一个盒子中糖的个数的数学期望. 期望公式为: E=∑ ...
最新文章
- 编写函数求两个整数 a 和 b 之间的较大值。要求不能使用if, while, switch, for, ?: 以 及任何的比较语句。...
- luogu P4745 [CERC2017]Gambling Guide(期望DP + 最短路实现)
- Spring Cloud【Finchley】-17 使用Zuul为单个或全部微服务提供容错与回退功能
- 实验7.2 二维数组 7-8 螺旋方阵
- insert 多条数据 并且具有唯一标识符
- git(12)---Git的基础知识
- xhell启动mysql_xshell怎么搭建mysql
- jsp文字上下居中显示_如何让任务栏完全透明,图标居中
- 麦克纳姆轮平台坐标系说明
- 423.从英文中重建数字
- Cisco ASA 5585防火墙ASDM配置
- Error running ...: No jdk for module
- 产品手册API文档模板
- jQuery的下载与基本使用
- VC操作excel(创建表格 查找 插入数据)
- python转写java踩坑记录
- Apache服务部署静态网站——个人用户主页
- 播客接棒在线音频的盈利梦
- 熊猫烧香病毒技术分析及应急解决方案
- hp1005mfp打印机驱动下载,打印机驱动安装方法
热门文章
- Amazon EKS 版本管理策略与升级流程
- 【独行秀才】macOS Monterey 12.0 Beta4(21A5294g)原版镜像
- 计算机网络在信息时代的作用
- 【内网安全】基础知识:工作组、域和权限分配
- 存储资源 存储设备 数据存储
- 扬州大学研究生计算机专业分数线,扬州大学考研历年分数线汇总
- 如何在PS(Adobe Photoshop)安装Portraiture3插件教程
- 如何永久关闭QQ广告弹窗
- python问题 Traceback (most recent call last)
- Flink No operators defined in streaming topology. Cannot execute.