Wordfish
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1082 Accepted: 535

Description

You have been tasked to infiltrate a tight-lipped society for fun and profit: the ACM ICPC regional judges. Through the PC2 “submission” software, you know that classified information is accessible through the log-ins of the judges tasked to a particular “regional site”. However, you are not certain that any particular judge has access to all the relevant information, so several log-ins will be required. You have been handed down a list of usernames, and the passwords used can be derived from these usernames, as follows:

Input

The input will only have capital letters (denoting the usernames) and carriage returns. Each line (thus each username) will not be longer than twenty characters, and there will not be more than 12 “judges” whose log-ins you will need to infiltrate. Strangely, no username uses any letter more than once.

Output

For each username, you must produce a line containing the password of length within 20 which that username uses. The password for a given username is determined from the twenty-one lexicographically consecutive permutations of the username, the eleventh (middle) of which is the username itself. For example, if the username is WORDFISH, the lexicographic permutations of WORDFISH contain, in order:

…, WOISHRFD, WOISRDFH, WOISRDHF, WOISRFDH, WOISRFHD, WOISRHDF, WOISRHFD, WORDFHIS, WORDFHSI, WORDFIHS, WORDFISH, WORDFSHI, WORDFSIH, WORDHFIS, WORDHFSI, WORDHIFS, WORDHISF, WORDHSFI, WORDHSIF, WORDIFHS, WORDIFSH, …

The password is then the permutation among the twenty-one lexicographically consecutive permutations of the username which has the largest minimum absolute distance between consecutive letters (and the first amongst the lexicographically ordered, if several permutations have the largest minimum absolute distance), followed by that minimum absolute distance. For the username WORDFISH, the password is WORDHSFI3.

Sample Input

WORDFISH

Sample Output

WORDHSFI3

Source

Manila 2006

Regionals 2006 >> Asia - Manila

问题链接:POJ3359 UVA1209 LA3173 Wordfish
问题简述:(略)
问题分析
    虽然是一个简单题,还是用到了全排列函数,值得了解细节。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* POJ3359 UVA1209 LA3173 Wordfish */#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <climits>using namespace std;int diff(string& s)
{int mind = INT_MAX;for(int i = 0; i < (int)s.size() - 1; i++)mind = min(mind, abs(s[i + 1] - s[i]));return mind;
}bool cmp(pair<string, int> a, pair<string, int> b)
{return a.second == b.second ? a.first > b.first : a.second > b.second;
}int main()
{string usr, usr2;while(cin >> usr) {vector<pair<string, int> > vp;usr2 = usr;for(int i = 1; i <= 10; i++) {prev_permutation(usr.begin(), usr.end());vp.push_back(make_pair(usr, diff(usr)));}vp.push_back(make_pair(usr2, diff(usr2)));for(int i = 1; i <= 10; i++) {next_permutation(usr2.begin(), usr2.end());vp.push_back(make_pair(usr2, diff(usr2)));}sort(vp.begin(), vp.end(), cmp);int d = vp[0].second;for(int i = 0; i < (int)vp.size(); i++) {if(vp[i].second < d) {printf("%s%d\n", vp[i - 1].first.c_str(), vp[i - 1].second);break;}if(d == 1) {printf("%s%d\n", vp[(int)vp.size() - 1].first.c_str(), vp[(int)vp.size() - 1].second);break;}}}return 0;
}

POJ3359 UVA1209 LA3173 Wordfish【Ad Hoc】相关推荐

  1. Bailian4137 最小新整数【Ad Hoc】

    4137:最小新整数 总时间限制: 1000ms 内存限制: 65536kB 描述 给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0.n的位数为m. ...

  2. Bailian4040 买书问题【Ad Hoc】

    4040:买书问题 总时间限制: 1000ms 内存限制: 65536kB 描述 某网上书店举行优惠促销,现有两种优惠策略.策略一是购书总额大于100元的可享受免费送货.策略二是如果购书数量大于3本, ...

  3. UVA10945 Mother bear【Ad Hoc】

    Unforunately for our lazy "heroes", the nuts were planted by an evil bear known as- Dave, ...

  4. UVA11309 Counting Chaos【Ad Hoc】

    Wolfgang Puck's rival, Emeril Lagasse ("BAM!"), recently set the world culinary record in ...

  5. UVA11942 Lumberjack Sequencing【Ad Hoc】

    Another tale of lumberjacks?. Let see -     The lumberjacks are rude, bearded workers, while foremen ...

  6. UVA11764 Jumping Mario【Ad Hoc】

    Mario is in the final castle. He now needs to jump over few walls and then enter the Koopa's Chamber ...

  7. POJ2940 HDU1489 UVA11054 Wine Trading in Gergovia【Ad Hoc】

    Wine Trading in Gergovia Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3541   Accepte ...

  8. UVA10189 Minesweeper【Ad Hoc】

    Have you ever played Minesweeper? It's a cute little game which comes within a certain Operating Sys ...

  9. UVA344 UVALive5452 Roman Digititis【Ad Hoc】

    Many persons are familiar with the Roman numerals for relatively small numbers. The symbols "i& ...

最新文章

  1. 体质测试java代码_求java代码,要求做一个测试类,实现以下功能之一。最好三个功能都有。...
  2. linux哪个命令可以切换工作目录?如何显示当前所在的目录,Linux cd命令:切换目录...
  3. Scrapy 教程(十)-管道与数据库
  4. spring cloud gateway集成hystrix全局断路器
  5. QQ连连看棋盘数组找法:
  6. css3:border-radius圆角边框详解 (变圆 图片)
  7. python动态视频下载器
  8. Oracle CoherenceWebLogic反序列化远程代码执行漏洞安全风险通告
  9. 深度学习(三)----算法岗面试题
  10. 读书笔记--精通CSS高级Web标准解决方案(一)---CSS基础
  11. Windows10新版本设置卓越性能
  12. 将linux系统移动硬盘,着手打造你的随身系统---将linux装进移动硬盘
  13. 五、数组(高琪java300集+java从入门到精通笔记)
  14. 鸟哥的linux私房菜-基础学习篇 读书笔记
  15. ASR6601牛羊定位器芯片GPS国内首颗支持LoRa的LPWAN SoC
  16. Centos7 lvm
  17. web前端学习路线-20个真实web开发项目集合
  18. MVC AJAXPro
  19. 醍醐灌顶之-线性代数-矩阵论
  20. 黑马瑞吉外卖之菜品的启售停售

热门文章

  1. STM32 AES 加解密流程梳理
  2. java手机太亮,Android 亮度调节
  3. java 反射 接口工具类_Java 反射工具类 ReflectionUtils
  4. Confluence介绍与使用
  5. Java多线程(五)——多线程的多线程池
  6. Arcgis Javascript那些事儿(七)--AMD详解
  7. 从SDE库文件手工删除SDE图层(转载)
  8. 官方文档——一篇文章弄懂Flutter中的布局
  9. 说服力:从场景化出发的用户价值
  10. Starling常见问题解决办法