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. Python_oldboy_自动化运维之路(四)

    本节内容 集合 字符编码与转码 函数语法及基本特性 函数参数与局部变量 返回值和嵌套函数 递归 匿名函数 高阶函数 1.集合 集合是一个无序的,不重复的数据组合,它的主要作用如下: 去重,把一个列表变 ...

  2. 原生JS实现AJAX、JSONP及DOM加载完成事件

    一.JS原生Ajax ajax:一种请求数据的方式,不需要刷新整个页面:ajax的技术核心是 XMLHttpRequest 对象:ajax 请求过程:创建 XMLHttpRequest 对象.连接服务 ...

  3. find命令的使用

    在以.conf结尾的文件里面查找含有aaa字符串的那一行   ( -name后面可以写  "*.*"   即匹配所有的文件 ) find / -name "*.conf& ...

  4. OBJECT_ID()的使用方法

    数据库中每个对像都有一个唯一的ID值,用Object_name(id)可以根据ID值得到对像的名称,object_id(name)可以根据对像名称得到对象的ID object_id()只能返回用户创建 ...

  5. drools7 (三、kmodule 介绍)

    注意几点: 1. kmodule 有默认的加载路径, 看  KieModuleModelImpl 这个类的源代码 public class KieModuleModelImpl implements ...

  6. markdown 语法规则

    markdown 语法规则 参考Markdown--入门指南 也可以参考这篇 Markdown: Basics (快速入门) 一级标题 二级标题 三级标题 列表 无序 1 2 3 有序 1 2 3 需 ...

  7. 【LOJ】 #2545. 「JXOI2018」守卫

    题解 只会蠢蠢的\(n^3\)--菜啊-- 我们发现最右的端点一定会选,看到的点一定是当前能看到的斜率最小的点变得更小一点,记录下这个点,在我们遇到一个看不到的点的时候,然后只用考虑R到它斜率最小的这 ...

  8. bzoj 1820 dp

    最普通dp要4维,因为肯定有一个在上一个的位置,所以可以变为3维,然后滚动数组优化一下. #include<bits/stdc++.h> #define LL long long #def ...

  9. 富文本是在modal框中弹出显示的问题

    记录一下,在用tinymce富文本的时候,由于是用在modal 上的,始终无法获取焦点,后来才发现问题出在tinymce在modal前创建了,所以导致这个问题,解决方案就是用 v-if="v ...

  10. CentOS 打包压缩文件 zip 命令详解

    我们再linux中常见的压缩文件有.tar.gz,.zip,.gz,在linux中,你要习惯没有.rar的日子. 一下为tar,zip命令详解 tar -zcvf /home/files.tar.gz ...