hdu1015 Safecracker (暴力枚举)
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
"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."
11700519 ZAYEXIWOVU
3072997 SOUGHT
1234567 THEQUICKFROG
0 END
YOXUZ
GHOST
no solution
五重循环 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 (暴力枚举)的更多相关文章
- HDU 1015.Safecracker【暴力枚举】【8月17】
Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is lo ...
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- 2014牡丹江网络赛ZOJPretty Poem(暴力枚举)
/* 将给定的一个字符串分解成ABABA 或者 ABABCAB的形式! 思路:暴力枚举A, B, C串! */ 1 #include<iostream> #include<cstri ...
- HNU 12886 Cracking the Safe(暴力枚举)
题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12886&courseid=274 解题报告:输入4个数 ...
- 51nod 1116 K进制下的大数 (暴力枚举)
题目链接 题意:中文题. 题解:暴力枚举. #include <iostream> #include <cstring> using namespace std; ; ; ch ...
- Codeforces Round #349 (Div. 1) B. World Tour 最短路+暴力枚举
题目链接: http://www.codeforces.com/contest/666/problem/B 题意: 给你n个城市,m条单向边,求通过最短路径访问四个不同的点能获得的最大距离,答案输出一 ...
- bzoj 1028 暴力枚举判断
昨天梦到这道题了,所以一定要A掉(其实梦到了3道,有两道记不清了) 暴力枚举等的是哪张牌,将是哪张牌,然后贪心的判断就行了. 对于一个状态判断是否为胡牌,1-n扫一遍,然后对于每个牌,先mod 3, ...
- POJ-3187 Backward Digit Sums (暴力枚举)
http://poj.org/problem?id=3187 给定一个个数n和sum,让你求原始序列,如果有多个输出字典序最小的. 暴力枚举题,枚举生成的每一个全排列,符合即退出. dfs版: #in ...
- hihoCoder #1179 : 永恒游戏 (暴力枚举)
题意: 给出一个有n个点的无向图,每个点上有石头数个,现在的游戏规则是,设置某个点A的度数为d,如果A点的石子数大于等于d,则可以从A点给每个邻接点发一个石子.如果游戏可以玩10万次以上,输出INF, ...
随机推荐
- java基础59 JavaScript运算符与控制流程语句(网页知识)
1.JavaScript运算符 1.1.加减乘除法 加法:+(加法,连接符,正数) true是1,false是0 减法:- 乘法:* 除法:/ 1.2.比较运算符 ...
- 如何学习React--[转]
如果你是一个 React (或者前端) 新手, 出于以下的原因, 你可能会对这个生态圈感到困惑: React 的目标群体历来是喜欢尝试新事物的开发者和前端专家. Facebook 只开源了他们在实际使 ...
- hihoCoder #1184 : 连通性二·边的双连通分量(边的双连通分量模板)
#1184 : 连通性二·边的双连通分量 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 在基本的网络搭建完成后,学校为了方便管理还需要对所有的服务器进行编组,网络所的老 ...
- 34、疯狂java讲义第三版
内容中包含 base64string 图片造成字符过多,拒绝显示
- PHP的XML Parser(转)
PHP处理XML文件 一.读取,更新(创建或者操作)一个XML文档,需要XML解析器 .有两种XML parsers: 1. Tree-based parser:将XML文档转化为DOM Tree结构 ...
- php取得当前时间函数
php取得当前时间函数文章提供了php的几种获取当前时间的函数,date,time等哦,同时告诉我如何解决时区问题哦. php获取当前时间 使用函式 date() 实现 <?php echo $ ...
- HTML5元素1
文档和元数据元素 元素 说明 类型 HTML5与其他的变化 base 设置相对URL的基础 元数据 无变化 body 表示HTML文档的内容 无 有变化 DOCTYPE 表示HTML文档的开始 无 有 ...
- glBlendFunc的几种常用情况
先Mark一下,后面有时间补上DEMO 1.画航母大灯,手电筒(效果为:透过黑色半透明层可看到下面的背景图,仅圆圈部分) 1)先画圆圈 2)再画背景图(大背景) 大背景设置 glBlendFunc ...
- 拥抱 Android Studio 之一:从 ADT 到 Android Studio
http://kvh.io/cn/embrace-android-studio-migration.html 1. 拥抱变化,拥抱新事物 Android Studio(IntelliJ IDEA)vs ...
- 8-2 Building for UN Uva1605
题意:你的任务是设计一个包含若干层的联合国大楼,其中每层都是一个等大的网络 由若干个国家需要在联合国大楼里面办公 你需要把每个格子分配给一个国家 使得任意两个不同的国家都有一对相邻的格子 (要没是同 ...