HDU 1015 Safecracker【数值型DFS】
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3966 Accepted Submission(s): 2028
"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."
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char a[], b[];
int visit[];
int n,num,len;
bool judge = false; bool cmp(char a, char b)
{
return a>b;
}
void init()
{
len = strlen(a);
judge = false;
memset(visit,,sizeof(visit));
sort(a,a+len,cmp);
for(int i = ;i<len;++i){
a[i] = a[i] -'A' + ;
}
}
void lnit()
{
for(int i = ;i<;++i)
b[i] = b[i]+'A'-;
}
bool check()
{
if(n == b[] - b[]*b[] + b[]*b[]*b[] - b[]*b[]*b[]*b[] + b[]*b[]*b[]*b[]*b[]){
judge = true;
return true;
}else return false;
}
void dfs(int depth)
{
//递归边界
if(judge) return;
if(depth == ) {check(); return;}
for(int i = ;i<len;++i){
if(!visit[i]&&!judge){
b[depth] = a[i];
visit[i] = ;
dfs(depth+);
visit[i] = ;
}
}
}
int main()
{ //freopen("in.txt","r",stdin);
while(scanf("%d %s",&n,a)&& !(n== && !strcmp(a,"END"))){
init();
dfs();
lnit();
if(judge)printf("%s\n",b);
else printf("no solution\n");
}
return ;
}
数值型DFS
HDU 1015 Safecracker【数值型DFS】的更多相关文章
- HDOJ(HDU).1015 Safecracker (DFS)
HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...
- HDU 1427 速算24点【数值型DFS】
速算24点 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1015 Safecracker 水题一枚
题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...
- HDU 2660 Accepted Necklace【数值型DFS】
Accepted Necklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 1015 Safecracker (DFS)
题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中 ...
- HDU 1015 Safecracker
解题思路:这题相当诡异,样例没过,交了,A了,呵呵,因为理论上是可以通过的,所以 我交了一发,然后就神奇的过了.首先要看懂题目. #include<cstdio> #include< ...
- HDOJ/HDU 1015 Safecracker(深搜)
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
- ZOJ 1403&&HDU 1015 Safecracker【暴力】
Safecracker Time Limit: 2 Seconds Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 ...
- HDU 1015 Safecracker(第一次用了搜索去遍历超时,第二次用for循环能够了,思路一样的)
Safecracker Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total S ...
随机推荐
- JSP语法,运行机理等
JSP是几年前就接触了,但是用归用,很多实际的意义含义等还是不太明白,借此机会,梳理一下. 1.JSP运行原理:当浏览器web应用服务器请求一个JSP页面时,Web应用服务器将其转换成一个Servle ...
- [Book Content]Python进阶
python进阶 原书内容https://github.com/eastlakeside/interpy-zh 通过记录书本目录和大概内容做一个记录,方便以后回顾检索. Chapter Title B ...
- CommonJs/ES6/AMD模块的用法以及区别
github地址: 一直以来对CommonJs/AMD/CMD/ES6的文件模块加载一直懵懵懂懂.甚至有时会将CommonJs的exports和ES6的export.default搞混.趁着学习web ...
- 精通javascript笔记(智能社)——简易tab选项卡及应用面向对象方法实现
javascript代码(常规方式/面向过程): <script type="text/javascript"> window.onload=function(){ v ...
- AOP编程的常用实现方式
aop代理分为静态代理.jdk动态代理.cglib动态代理 通过动态代理的方式实现横向扩展,实现权限校验.日志等功能. jdk静态代理:代理类和委托类实现同一接口,并且在代理类中需要硬编码接口. jd ...
- 【BZOJ2301】【HAOI2011】Problem b [莫比乌斯反演]
Problem b Time Limit: 50 Sec Memory Limit: 256 MB[Submit][Status][Discuss] Description 对于给出的n个询问,每次 ...
- loj6100 「2017 山东二轮集训 Day1」第一题
传送门:https://loj.ac/problem/6100 [题解] 我们考虑维护从某个端点开始的最长满足条件的长度,如果知道了这个东西显然我们可以用主席树来对每个节点建棵关于右端点的权值线段树, ...
- 创建堆 HeapCreate
创建额外的堆的原因1.对组件进行保护2.更有效的内存管理3.局部访问4.避免线程同步开销5.快速释放 HeapCreate函数原型:HANDLE WINAPI HeapCreate( _In_ DWO ...
- C++11 自动释放锁(转)
原文转自 https://blog.csdn.net/lmb1612977696/article/details/77712170 c++11加入了很多新的特性,值得我们去探索. 先看一个例子:普通的 ...
- Google Intern
申请 事情应该从去年(2013)说起,好基友从百度离职跳到了Google,回学校打印本科成绩单,然后晚上在scuacm群里,结果Dr. zuo问我想去实习么,正好有学长可以内推. 于是乎写了简历,然后 ...