HDUOJ----Safecracker(1015)
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6779 Accepted Submission(s): 3370
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
#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)的更多相关文章
- MySQL实战45讲(10--15)-笔记
11 | 怎么给字符串字段加索引? 维护一个支持邮箱登录的系统,用户表是这么定义的: mysql> create table SUser( ID bigint unsigned primary ...
- HDU 1015 Safecracker (DFS)
题意:给一个数字n(n<=12000000)和一个字符串s(s<=17),字符串的全是有大写字母组成,字母的大小按照字母表的顺序,比如(A=1,B=2,......Z=26),从该字符串中 ...
- Safecracker(搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1015 / 题意; 从所给的一串字符串中选出5个字母假如是(A B C D E)使得A-B^2+C^3-D^4+E ...
- HDOJ-1015 Safecracker(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=1015 题意:给出一个目标值target和一个由大写字母组成的字符串 A-Z分别对应权值1-26 要求从给出的字符 ...
- 院校-美国:麻省理工学院(MIT)
ylbtech-院校-美国:麻省理工学院(MIT) 麻省理工学院(Massachusetts Institute of Technology),简称麻省理工(MIT),坐落于美国马萨诸塞州波士顿都市区 ...
- PAT 甲级 1015 Reversible Primes(20)
1015 Reversible Primes(20 分) A reversible prime in any number system is a prime whose "reverse& ...
- PAT (Basic Level) Practise (中文)- 1015. 德才论 (25)
http://www.patest.cn/contests/pat-b-practise/1015 宋代史学家司马光在<资治通鉴>中有一段著名的“德才论”:“是故才德全尽谓之圣人,才德兼亡 ...
- PAT(B)1015 德才论(C)
题目链接:1015 德才论 (25 point(s)) 分析 由题意可知,需要将考生按照分数进行一个分类(级),然后在每一级中按照分数排序.输入的时候将每个人的总分,等级和录取人数先算出来.然后按照自 ...
- LFYZ-OJ ID: 1015 统计数字(NOIP2007)
分析 本体思路很简单:读入数据,排序.统计.输出.难点在于数据量较大,选择何种排序方法就极为重要,否则很容易发生内存或时间超限.可以考虑以下几种思路: 桶排序 桶排序是可以想到的最简单方法,可在O(n ...
随机推荐
- 学习笔记:STL
第一部分:(参考百度百科) 一.STL简介 STL(Standard Template Library,标准模板库)是惠普实验室开发的一系列软件的统称.它是由Alexander Stepanov.Me ...
- 第六章 memcached剖析
注:本篇博客参考于两本书. <memcached全面剖析>,该书籍市面上应该没有,我传到了百度云盘,链接如下:http://pan.baidu.com/s/1qX00Lti <大型网 ...
- iOS开发-UIWebView加载本地和网络数据
UIWebView是内置的浏览器控件,可以用它来浏览网页.打开文档,关于浏览网页榜样可以参考UC,手机必备浏览器,至于文档浏览的手机很多图书阅读软件,UIWebView是一个混合体,具体的功能控件内置 ...
- Oracle服务启动顺序导致ORA-12514
在window 上装了oracle11g,按照常规步骤安装完成后一切OK,如下图所示 C:\Users\Administrator>sqlplus /nolog SQL*Plus: Releas ...
- OAuth 2.0 Authorization Framework RFC
Internet Engineering Task Force (IETF) D. Hardt, Ed.Request for Comments: 6749 MicrosoftObsoletes: 5 ...
- sed 常用的命令
n: 读取一行,执行n,把当前行打印到标准输出,再读取一行,覆盖当前行,然后对模式空间执行一组模式/行为.N:读取一行,执行N,再读取一行,现在模式空间有两行内容,执行一组模式/行为.如下:[root ...
- Winform控件之DataGridView数据控件显示问题
近期在做同类的信息记录管理系统时遇到了DataGridView数据控件的显示问题.可能是2015年的上半年没有深入 学习C#开发的原因.这几天又一次搬出来开发,首先遇到的问题就是动态绑定数据显示的问题 ...
- U盘去保护方法
一.基本信息 U盘大小是16G的,估计用了2G的空间存储,没有任何开关设置,格式化或写入时提示被写保护: U盘放到任何一台电脑上都是只能读不能写,说明与电脑无关,用了各种U盘修复程序都无效: 二.一般 ...
- Python编程-Office操作-操作Excel(上)
首先,需要安装openpyxl库 http://openpyxl.readthedocs.org/en/default/ pyton 2.xpip install openpyxl python 3. ...
- 执行Socket socket = new Socket(ip, port);时抛出个异常:android.os.NetworkOnMainThreadException解决办法
首先,确认你的android版本是4.0之后再用此方法解决,因为在4.0之后在主线程里面执行Http请求才会报这个错,也许是怕Http请求时间太长造成程序假死的情况吧.Android在4.0之前的版本 ...