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 ...
随机推荐
- 【UOJ Round #8】
A 一道不错的题,虽然大家都觉得是水题,然而蒟蒻我想出来的好慢……Orz alpq 发现其实就是一个网格图,每一个大块都是同一颜色……横纵坐标互不干扰…… //UOJ Round #8 A #incl ...
- cmake函数參数解析
近期在迁移公司的make系统到cmake上.发现cmake的function參数非常奇怪.比如,假设我们向一个function传递list作为參数,在function中,形參会变成例如以下状况: se ...
- 如何关掉UAC?
你可能会问, 这也值得一写? 唉, 怎么说呢, 谁让咱一开始不会呢. ^_^ 好记性不如烂笔头嘛. 1. 打开一个command prompt, 输入msconfig回车. 2. 点击tools选 ...
- A12_ListView & ExpandablelistView
一.ListView 效果: 1.activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/a ...
- rcp(插件开发) The 'Eclipse-LazyStart' header is deprecated, use 'Bundle-ActivationPolicy'
'Eclipse-LazyStart' 这个规范在3.4 osgi 4.1 以后就不支持了 大家使用Bundle-ActivationPolicy: lazy 这个属性来实现插件的懒加载吧!
- 解决Sqlserver 2008 R2在创建登录名出错"此版本的 Microsoft Windows 不支持 MUST_CHANGE 选项。 (Microsoft SQL Server,错误: 15195)"
错误信息: 执行 Transact-SQL 语句或批处理时发生了异常. (Microsoft.SqlServer.ConnectionInfo) 此版本的 Microsoft Windows ...
- 廖雪峰的python学习网址
http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00140737570055886 ...
- (转)U3D DrawCall优化手记
自:http://www.cnblogs.com/ybgame/p/3588795.html 在最近,使用U3D开发的游戏核心部分功能即将完成,中间由于各种历史原因,导致项目存在比较大的问题,这些问题 ...
- 机器视觉之 ICP算法和RANSAC算法
临时研究了下机器视觉两个基本算法的算法原理 ,可能有理解错误的地方,希望发现了告诉我一下 主要是了解思想,就不写具体的计算公式之类的了 (一) ICP算法(Iterative Closest Poin ...
- [Node.js]26. Level 5 : Route rendering
Instead of just writing out the quote to the response, instead render the quote.ejs template, passin ...