hdu 1015(DFS)
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 13237 Accepted Submission(s): 6897
"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<cmath>
#include<map>
#include<cstdlib>
#include<vector>
#include<set>
#include<queue>
#include<cstring>
#include<string.h>
#include<algorithm>
#define INF 0x3f3f3f3f
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N = 1e6+;
const ll mod = 1e9+;
char s[];
int a[];
int b[];
int visited[];
int n;
int flag=;
void DFS(int t){
if(flag==)return;
if(t==){
int sum1=b[]+b[]*b[]*b[]+b[]*b[]*b[]*b[]*b[];
int sum2=b[]*b[]+b[]*b[]*b[]*b[];
if(sum1-sum2==n){
flag=;
printf("%c%c%c%c%c\n",b[]-+'A',b[]-+'A',b[]-+'A',b[]-+'A',b[]-+'A');
return ;
}
return ;
}
for(int i=;i>=;i--){
if(visited[i]==)continue;
else if(visited[i]==&&a[i]==){
visited[i]=;
b[t]=i;
DFS(t+);
visited[i]=;
}
}
}
int main(){
while(scanf("%d %s",&n,s)!=EOF){
if(n==&&strcmp(s,"END")==)break;
int len=strlen(s);
flag=;
memset(a,,sizeof(a));
for(int i=;i<len;i++){
int tt=s[i]-'A'+;
a[tt]=;
}
memset(visited,,sizeof(visited));
DFS();
if(flag==)cout<<"no solution"<<endl; } }
hdu 1015(DFS)的更多相关文章
- HDOJ(HDU).1015 Safecracker (DFS)
HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...
- hdu 1342(DFS)
Lotto Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- F - JDG HDU - 2112 (最短路)&& E - IGNB HDU - 1242 (dfs)
经过锦囊相助,海东集团终于度过了危机,从此,HDU的发展就一直顺风顺水,到了2050年,集团已经相当规模了,据说进入了钱江肉丝经济开发区500强.这时候,XHD夫妇也退居了二线,并在风景秀美的诸暨市浬 ...
- F - Auxiliary Set HDU - 5927 (dfs判断lca)
题目链接: F - Auxiliary Set HDU - 5927 学习网址:https://blog.csdn.net/yiqzq/article/details/81952369题目大意一棵节点 ...
- hdu - 1072(dfs剪枝或bfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1072 思路:深搜每一个节点,并且进行剪枝,记录每一步上一次的s1,s2:如果之前走过的时间小于这一次, ...
- HDU——2647Reward(DFS或差分约束)
Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- P - Sudoku Killer HDU - 1426(dfs + map统计数据)
P - Sudoku Killer HDU - 1426 自从2006年3月10日至11日的首届数独世界锦标赛以后,数独这项游戏越来越受到人们的喜爱和重视. 据说,在2008北京奥运会上,会将数独列为 ...
- hdu 1142(DFS+dijkstra)
#include<iostream> #include<cstdio> #include<cmath> #include<map> #include&l ...
- hdu 1181(DFS)变 形 课
变形课 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submis ...
随机推荐
- javaScript 正则表达式匹配日期
// yyyyMMddhhmmss var pattern = /^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(? ...
- ViewPager+Fragment实现页面的切换
新知识,新摘要: 效果图:framgent导入包都是v4包下,谨慎导入错误! 首先设置viewPager布局: <?xml version="1.0" encoding=&q ...
- linux学习笔记--文件
文件系统 ls -lhi i inode 相当于文件在磁盘里的唯一标示,index node h 代表文件大小k,m [root@masters ~]# [root@masters ~]# ls -l ...
- Android自定义控件
开发自定义控件的步骤: 1.了解View的工作原理 2. 编写继承自View的子类 3. 为自定义View类增加属性 4. 绘制控件 5. 响应用户消息 6 .自定义回调函数 一.Vie ...
- 最近遇到的jsfl开发问题总结
最近在用jsfl开发一套把MUGEN角色动画和数据导入flash的脚本.遇到不少问题,这里备忘一下: 1.绘制笔刷和填充的问题 更换填充和笔刷需要用如下的代码 而不是随便设置一下doc的属性 var ...
- android之handle
Android中异步消息处理主要由四个部分组成,Message.handler.messageQueue和looper. 1.message message是线程之间传递的消息,他可以在内部携带少量的 ...
- Android版本4.0~7.0
Android 4.0 Ice Cream Sandwich(冰激凌三明治):2011年10月19日发布 版本主要更新如下:全新的UI:全新的Chrome Lite浏览器:截图功能:更强大的图片编辑功 ...
- iOS强制横屏
由于项目需求,需要整个项目页面都是竖屏,唯独一个折线图页面强制性横屏显示. 网上逛了许多帖子,也看了好多大神的提供的方法,都没能够实现本屌丝想要的效果.没办法自己研究自己搞,借鉴各路大神的思路,最后费 ...
- opencv单目摄像机标定
#include <cv.h> #include <highgui.h> #include <iostream> #include <stdio.h> ...
- python实验二:字符串排序
##统计word中的各个字符的出现的次数,并统计出所有前十名的字符使用次数 # -*- coding:utf-8 -*- word='''awfesdafhjkcasadckjsdackjsadvcn ...