http://acm.hdu.edu.cn/showproblem.php?pid=1015

Safecracker

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6327    Accepted Submission(s): 3160

Problem Description
=== Op tech briefing, 2002/11/02 06:42 CST === 

"The item is locked in a Klein safe behind a painting in the second-floor library. Klein safes are extremely rare; most of them, along with Klein and his factory, were destroyed in World War II. Fortunately old Brumbaugh from research knew Klein's secrets and wrote them down before he died. A Klein safe has two distinguishing features: a combination lock that uses letters instead of numbers, and an engraved quotation on the door. A Klein quotation always contains between five and twelve distinct uppercase letters, usually at the beginning of sentences, and mentions one or more numbers. Five of the uppercase letters form the combination that opens the safe. By combining the digits from all the numbers in the appropriate way you get a numeric target. (The details of constructing the target number are classified.) To find the combination you must select five letters v, w, x, y, and z that satisfy the following equation, where each letter is replaced by its ordinal position in the alphabet (
A=1, B=2, ..., Z=26). The combination is then vwxyz. If there is more than one solution then the combination is the one that is lexicographically greatest, i.e., the one that would appear last in a dictionary."

v - w^2 + x^3 - y^4 + z^5 = target 

"For example, given target 1 and letter set ABCDEFGHIJKL, one possible solution is FIECB, since 6 - 9^2 + 5^3 - 3^4 + 2^5 = 1. There are actually several solutions in this case, and the combination turns out to be LKEBA. Klein thought it was safe to encode the combination within the engraving, because it could take months of effort to try all the possibilities even if you knew the secret. But of course computers didn't exist then."

=== Op tech directive, computer division, 2002/11/02 12:30 CST ===

"Develop a program to find Klein combinations in preparation for field deployment. Use standard test methodology as per departmental regulations. Input consists of one or more lines containing a positive integer target less than twelve million, a space, then at least five and at most twelve distinct uppercase letters. The last line will contain a target of zero and the letters END; this signals the end of the input. For each line output the Klein combination, break ties with lexicographic order, or 'no solution' if there is no correct combination. Use the exact format shown below."

 
Sample Input
1 ABCDEFGHIJKL
11700519 ZAYEXIWOVU
3072997 SOUGHT
1234567 THEQUICKFROG
0 END
 
Sample Output
LKEBA
YOXUZ
GHOST
no solution
 
Source
 
Recommend
JGShining
 

五重循环 AC~

暴力无处不在~

#include <cstdio>
#include <cstring>
#include <iostream>
#include <functional>
#include <algorithm>
using namespace std;
int a[15];
int sum, n; void solve() {
int v, w, x, y, z;
for(v=0; v<n; v++)
for(w=0; w<n; w++)
if(w!=v)
for(x=0; x<n; x++)
if(x!=v&&x!=w)
for(y=0; y<n; y++)
if(y!=v&&y!=w&&y!=x)
for(z=0; z<n; z++)
if(z!=v&&z!=w&&z!=x&&z!=y) {
if(sum == a[v]-a[w]*a[w]+a[x]*a[x]*a[x]-a[y]*a[y]*a[y]*a[y]+a[z]*a[z]*a[z]*a[z]*a[z]) {
printf("%c%c%c%c%c\n",a[v]+'A'-1,a[w]+'A'-1,a[x]+'A'-1,a[y]+'A'-1,a[z]+'A'-1);
return ;
}
}
printf("no solution\n");
}
int main() {
int i;
char str[15];
while(scanf("%d%s",&sum,str),sum) {
n =strlen(str);
for(i=0; i<n; i++)
a[i] = str[i]-'A'+1;
sort(a,a+n,greater<int>());
solve();
}
return 0;
}

hdu1015 Safecracker (暴力枚举)的更多相关文章

  1. HDU 1015.Safecracker【暴力枚举】【8月17】

    Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is lo ...

  2. CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)

    题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...

  3. 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)

    /* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...

  4. HNU 12886 Cracking the Safe(暴力枚举)

    题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...

  5. 51nod 1116 K进制下的大数 (暴力枚举)

    题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...

  6. Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举

    题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...

  7. bzoj 1028 暴力枚举判断

    昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...

  8. POJ-3187 Backward Digit Sums (暴力枚举)

    http://poj.org/problem?id=3187 给定一个个数n和sum,让你求原始序列,如果有多个输出字典序最小的. 暴力枚举题,枚举生成的每一个全排列,符合即退出. dfs版: #in ...

  9. hihoCoder #1179 : 永恒游戏 (暴力枚举)

    题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...

随机推荐

  1. java 多线程总结篇3之——生命周期和线程同步

    一.生命周期 线程的生命周期全在一张图中,理解此图是基本: 线程状态图 一.新建和就绪状态 当程序使用new关键字创建了一个线程之后,该线程就处于新建状态,此时它和其他的Java对象一样,仅仅由Jav ...

  2. HDU 4763 Theme Section(KMP+枚举公共前后缀)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4763 题目大意: 给你一个字符串s,存在一个子串E同时出现在前缀.中间.后缀,即EAEBE这种模式,A ...

  3. (一)SpringMVC

    第一章 问候SpringMVC 第一节 SpringMVC简介 SpringMVC是一套功能强大,性能强悍,使用方便的优秀的MVC框架 下载和安装Spring框架: 登录http://repo.spr ...

  4. Java事务管理之Spring+Hibernate

    环境与版本 除了上一篇中的hibernate的相关lib 外 Java事务管理之Hibernate 还需要加入Spring的lib 包和如下的一些依赖包 org.aopallianceorg.aspe ...

  5. Django API验证(令牌)

    1. 获取接口信息 Client端 import requests import time import hashlib ctime = time.time() key = 'akfljakfjakl ...

  6. Fedora下Eclipse/MyEclipse崩溃的解决方案

    Fedora19下使用myeclipse2013时,打开不到一分钟就异常关闭. 默认在home目录下生成一个log文件,里面显示的错误信息,说是libsoup.so文件导致出错.第一个想法是删除这个文 ...

  7. appium----adb shell输入中文/Emoji表情符(ADBKeyBoard)

    前序 “adb shell input textyoyo“ 可以通过adb 输入英文的文本,由于不支持unicode编码,所以无法输入中文,github上有个国外的大神写了个ADBKeyBoard输入 ...

  8. RAII

    转载:http://www.jellythink.com/archives/101 什么是RAII? RAII是Resource Acquisition Is Initialization的简称,是C ...

  9. 在Ubuntu 16.04 安装python3.6 环境并设置为默认

    在Ubuntu 16.04 安装python3.6 环境并设置为默认 1.添加python3.6安装包,并且安装 sudo apt-get install software-properties-co ...

  10. linux服务开机启动

    1.chkconfig 配置开机启动 在  /etc/init.d  创建执行服务的可执行脚本,赋予脚本可执行权限.如果是通过yum 或者rpm安装的,并且已经在该目录下存在对应的启动脚本,就不用自己 ...