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. linux下so获得自己文件位置的路径

    打开这个设备/proc/self/maps 返回的就是这个进程当前使用的so列表 cat /proc/self/maps00400000-0040b000 r-xp 00000000 08:01 14 ...

  2. StatefulSet: Kubernetes 中对有状态应用的运行和伸缩

    在最新发布的 Kubernetes 1.5 我们将过去的 PetSet 功能升级到了 Beta 版本,并重新命名为StatefulSet.除了依照社区民意改了名字之外,这一 API 对象并没有太大变化 ...

  3. Asp.Net Core App 部署故障示例 1

    相关阅读:Windows + IIS 环境部署Asp.Net Core App 1.  HTTP Error 502.5 – Process Failure 环境 Windows Server 201 ...

  4. Java:字符串类简单的正则表达式

    class Test { public static void main(String[] args) { String str = "xia..as....yuan.com"; ...

  5. insert-delete-getrandom-o1-duplicates-allowed

    https://leetcode.com/problems/insert-delete-getrandom-o1-duplicates-allowed/ public class Randomized ...

  6. 变量声明置顶规则、函数声明及函数表达式和函数的arguments属性初始化

    一.变量声明和变量赋值: if (!("a" in window)) { ; } alert(a);//a为? 你可能认为alert出来的结果是1,然后实际结果是“undefine ...

  7. PREEMPT_RT的未来

    因为开发资金的问题,Thomas Gleixner宣布他已经不想干了. 商业公司往往用了PREEMPT_RT的功能去不愿意去回报社区,那就自己弄吧. http://lwn.net/Articles/6 ...

  8. Java程序调用带参数的shell脚本返回值

    Java程序调用带参数的shell脚本返回值 首先来看看linux中shell变量(\(#,\)@,$0,$1,\(2)的含义解释 变量说明: -  \)$  Shell本身的PID(ProcessI ...

  9. 在Ubuntu 桌面版 12.04 LTS安装并运行SSH

    第一步:安装openssh-server #sudo apt-get install openssh-server 第二步:查看ssh服务是否已经运行,执行 #ps -e | grep ssh 执行完 ...

  10. ASP.NET之旅--深入浅出解读IIS架构

    在学习Asp.net时,发现大多数作者都是站在一个比较高的层次上讲解Asp.Net. 他们耐心. 细致地告诉你如何一步步拖放控件. 设置控件属性.编写 CodeBehind代码,以实现某个特定的功能. ...