// 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相关推荐

  1. UVa Online Judge 工具網站

    UVa Online Judge 工具網站 转自http://www.csie.ntnu.edu.tw/~u91029/uva.html Lucky貓的ACM園地,Lucky貓的 ACM 中譯題目 M ...

  2. uva 10256 The Great Divide (Convex Hull, Simple)

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=14&page=sh ...

  3. 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 ...

  4. UVa 11027 - Palindromic Permutation 回文串,组合加搜索

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=s ...

  5. uva 11275 3D Triangles (3D-Geometry)

    uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem= ...

  6. UVa 207 - PGA Tour Prize Money

    时间限制:3.000秒 题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&catego ...

  7. UVa 1471 Defense Lines - 线段树 - 离散化

    题意是说给一个序列,删掉其中一段连续的子序列(貌似可以为空),使得新的序列中最长的连续递增子序列最长. 网上似乎最多的做法是二分查找优化,然而不会,只会值域线段树和离散化... 先预处理出所有的点所能 ...

  8. Ananagrams(sort+map) UVA - 156 统计字谜

    Ananagrams(sort+map) UVA - 156 统计字谜 Most crossword puzzle fans are used to anagrams - groups of word ...

  9. UVa 109 - SCUD Busters(凸包计算)

    题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...

  10. Candy UVA 1639 (数学期望)

    Candy UVA 1639 (数学期望) 有两个盒子各有n颗糖(n<=2*105),从两个盒子取糖的概率为p和1-p,直到一个盒子没糖,求另一个盒子中糖的个数的数学期望. 期望公式为: E=∑ ...

最新文章

  1. 编写函数求两个整数 a 和 b 之间的较大值。要求不能使用if, while, switch, for, ?: 以 及任何的比较语句。...
  2. luogu P4745 [CERC2017]Gambling Guide(期望DP + 最短路实现)
  3. Spring Cloud【Finchley】-17 使用Zuul为单个或全部微服务提供容错与回退功能
  4. 实验7.2 二维数组 7-8 螺旋方阵
  5. insert 多条数据 并且具有唯一标识符
  6. git(12)---Git的基础知识
  7. xhell启动mysql_xshell怎么搭建mysql
  8. jsp文字上下居中显示_如何让任务栏完全透明,图标居中
  9. 麦克纳姆轮平台坐标系说明
  10. 423.从英文中重建数字
  11. Cisco ASA 5585防火墙ASDM配置
  12. Error running ...: No jdk for module
  13. 产品手册API文档模板
  14. jQuery的下载与基本使用
  15. VC操作excel(创建表格 查找 插入数据)
  16. python转写java踩坑记录
  17. Apache服务部署静态网站——个人用户主页
  18. 播客接棒在线音频的盈利梦
  19. 熊猫烧香病毒技术分析及应急解决方案
  20. hp1005mfp打印机驱动下载,打印机驱动安装方法

热门文章

  1. Amazon EKS 版本管理策略与升级流程
  2. 【独行秀才】macOS Monterey 12.0 Beta4(21A5294g)原版镜像
  3. 计算机网络在信息时代的作用
  4. 【内网安全】基础知识:工作组、域和权限分配
  5. 存储资源 存储设备 数据存储
  6. 扬州大学研究生计算机专业分数线,扬州大学考研历年分数线汇总
  7. 如何在PS(Adobe Photoshop)安装Portraiture3插件教程
  8. 如何永久关闭QQ广告弹窗
  9. python问题 Traceback (most recent call last)
  10. Flink No operators defined in streaming topology. Cannot execute.