Safecracker

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

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
 搜索....dfs
代码:
 #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
char maze[],key[];
int str[];
/*rn长与cm寛*/
int n,cnt,cm,cmt;
int cmp(const void *a ,const void *b)
{
return *(char *)b-*(char *)a;
}
bool dfs(int step) /*深度搜索*/
{
if(step==&&(str[]-str[]*str[]+str[]*str[]*str[]-str[]*str[]*str[]*str[]+str[]*str[]*str[]*str[]*str[])==n) //单词有5个
{
return true;
}
/*如果没有找到,继续搜索*/
if(step<)
{
int i;
for( i=;i<cm;i++) //作为宽度
{
if(maze[i]) //不为0
{
key[cnt++]=maze[i];
str[cmt++]=maze[i]-;
maze[i]='\0';
if(dfs(step+))
return true;
maze[i]=key[--cnt];
key[cnt]='\0';
str[--cmt]=;
}
}
}
return false;
} int main()
{
while(scanf("%d %s",&n,maze)!=EOF)
{
if(n==&&strcmp(maze,"END")==) break;
cmt=cnt=;
cm=strlen(maze); /*作为搜索的数组*/
memset(key,'\0',sizeof(key));
memset(str,,sizeof(str));
qsort(maze,cm,sizeof(char),cmp);
if(dfs())
printf("%s\n",key);
else
printf("no solution\n");
}
return ;
}

HDUOJ----Safecracker(1015)的更多相关文章

  1. MySQL实战45讲(10--15)-笔记

    11 | 怎么给字符串字段加索引? 维护一个支持邮箱登录的系统,用户表是这么定义的: mysql> create table SUser( ID bigint unsigned primary ...

  2. HDU 1015 Safecracker (DFS)

    题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中 ...

  3. Safecracker(搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1015 / 题意; 从所给的一串字符串中选出5个字母假如是(A B C D E)使得A-B^2+C^3-D^4+E ...

  4. HDOJ-1015 Safecracker(DFS)

    http://acm.hdu.edu.cn/showproblem.php?pid=1015 题意:给出一个目标值target和一个由大写字母组成的字符串 A-Z分别对应权值1-26 要求从给出的字符 ...

  5. 院校-美国:麻省理工学院(MIT)

    ylbtech-院校-美国:麻省理工学院(MIT) 麻省理工学院(Massachusetts Institute of Technology),简称麻省理工(MIT),坐落于美国马萨诸塞州波士顿都市区 ...

  6. PAT 甲级 1015 Reversible Primes(20)

    1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...

  7. PAT (Basic Level) Practise (中文)- 1015. 德才论 (25)

    http://www.patest.cn/contests/pat-b-practise/1015 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡 ...

  8. PAT(B)1015 德才论(C)

    题目链接:1015 德才论 (25 point(s)) 分析 由题意可知,需要将考生按照分数进行一个分类(级),然后在每一级中按照分数排序.输入的时候将每个人的总分,等级和录取人数先算出来.然后按照自 ...

  9. LFYZ-OJ ID: 1015 统计数字(NOIP2007)

    分析 本体思路很简单:读入数据,排序.统计.输出.难点在于数据量较大,选择何种排序方法就极为重要,否则很容易发生内存或时间超限.可以考虑以下几种思路: 桶排序 桶排序是可以想到的最简单方法,可在O(n ...

随机推荐

  1. 【BZOJ】【3503】【CQOI2014】和谐矩阵

    高斯消元解Xor方程组 Orz ZYF o(︶︿︶)o 唉我的数学太烂了…… 错误思路:对每个格点进行标号,然后根据某5个异或和为0列方程组,高斯消元找自由元……(目测N^3会TLE) ZYF的正确思 ...

  2. Container With Most Water leetcode java

    题目: Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, a ...

  3. Maximal Rectangle leetcode java

    题目: Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones ...

  4. android中一些特殊字符(如:←↑→↓等箭头符号)的Unicode码值

    在项目中,有时候在一些控件(如Button.TextView)中要添加一些符号,如下图所示:                          这个时候可以使用图片的方式来显示,不过这些可以直接使用U ...

  5. Spring MVC 4.2 CORS 跨域访问

    跨站 HTTP 请求(Cross-site HTTP request)是指发起请求的资源所在域不同于该请求所指向资源所在的域的 HTTP 请求.比如说,域名A(http://domaina.examp ...

  6. Back Track 5 之 Web踩点 && 网络漏洞

    Web踩点 CMS程序版本探测 Blindelephant 针对WORDPRESS程序的踩点工具,通过比较插件等一系列的指纹,判断版本. 格式: Python Blindelephant.py [参数 ...

  7. 简单账本-用完即走的微信小程序

    作为一个记账强迫症患者,对当前手机中的记账App都不太满意.这类软件越来越臃肿,越来越慢,启动要半天.联网同步要半天,进入界面又有一堆新功能要介绍.好不容易开始记账,又得各种高大上的选择设定,一笔帐下 ...

  8. MySQL监控和预警

    https://blog.csdn.net/zhaowenbo168/article/details/53219860 1.摘要 本人从事Java Web开发,在项目开发中会用到很多中间件,本文主要介 ...

  9. Linux服务启动出现java.net.UnknownHostException:

    第一种情况: 一般是在/etc/hosts文件,在文件最后加入这句配置,重启服务即可   172.xx.xxx.xxx localhost.localdomain xxx-houtai1 第二种情况: ...

  10. Android之新建项目

    最近开始接触Android,实践出真理,接下来实际创建Android应用程序. 1.启动Eclipse,依次选择 " File/New/Project... " 或 " ...