HDU-1015(暴力)
Safecracker
"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."
11700519 ZAYEXIWOVU
3072997 SOUGHT
1234567 THEQUICKFROG
0 END
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
using namespace std;
#define INF 100000
typedef long long ll;
const int maxn=;
char letter[maxn];
int vis[];
int main()
{
int v;
while(scanf("%d%s",&v,letter)){
if(v==&&!strcmp(letter,"END")) break;
memset(vis,,sizeof(vis));
int n=strlen(letter);
for(int i=;i<n;i++){
vis[i]=letter[i]-'A'+;
}
sort(vis,vis+n);
int flag=;
for(int i=n-;i>=;i--){
if(flag) break;
for(int j=n-;j>=;j--){
if(flag) break;
if(j==i) continue;
for(int k=n-;k>=;k--){
if(flag) break;
if(k==i||k==j) continue;
for(int l=n-;l>=;l--){
if(flag) break;
if(l==i||l==j||l==k) continue;
for(int h=n-;h>=;h--){
if(h==l||h==k||h==j||h==i) continue;
if(vis[i]-pow(vis[j],)+pow(vis[k],)-pow(vis[l],)+pow(vis[h],)==v){
printf("%c%c%c%c%c\n",vis[i]-+'A',vis[j]-+'A',vis[k]-+'A',vis[l]-+'A',vis[h]-+'A');
flag=;
break;
}
}
}
}
} }
if(!flag) printf("no solution\n");
}
return ;
}
HDU-1015(暴力)的更多相关文章
- hdu 1015 Safecracker 水题一枚
题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...
- HDOJ(HDU).1015 Safecracker (DFS)
HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...
- HDU 1015.Safecracker【暴力枚举】【8月17】
Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is lo ...
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
- ZOJ 1403&&HDU 1015 Safecracker【暴力】
Safecracker Time Limit: 2 Seconds Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 ...
- HDU 6351暴力枚举 6354计算几何
Beautiful Now Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- HDU 5944 暴力
Fxx and string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)T ...
- hdu 4039 暴力
思路:用map将每个字符串与一个数字进行对应,然后暴力统计就好了 #include<cstring> #include<iostream> #include<cstdio ...
- HDU 1015 Safecracker 解决问题的方法
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kl ...
- hdu 4952 暴力
http://acm.hdu.edu.cn/showproblem.php?pid=4952 给定x,k,i从1到k,每次a[i]要是i的倍数,并且a[i]大于等于a[i-1],x为a0 递推到下一个 ...
随机推荐
- 三点经验:长时间运行函数需要随时发射信号报告进度,以及设置bool变量随时可以退出,每做一步操作必须及时记录和处理相关信息
三点经验:长时间运行函数需要随时发射信号报告进度,以及设置bool变量随时可以退出,每做一步操作必须及时记录和处理相关信息 不能到最后一起处理,否则万一中间出错了,这个记录状态就全部都乱了.
- git从指定的commit创建分支
How do I create a new git branch from an old commit? git checkout -b justin a9c146a09505837ec03b Thi ...
- centos6.5 无线网卡配置
来自:http://liqirui.blog.51cto.com/4662702/1344877 http://wiki.centos.org/zh/HowTos/Laptops/Wp ...
- 三招搞挂Mysql(转)
一.产生大量的undo日志 众所周知,InnoDB是一个支持MVCC的存储引擎,为了支持MVCC,InnoDB需要保存undo日志,以便对用户提供记录的历史版本.如果我们开启一个事务,反复地更新一条记 ...
- 【转】xcode APP 打包以及提交apple审核详细流程(新版本更新提交审核)
原文网址:http://blog.csdn.net/mad1989/article/details/8167529 最近项目到了最后的阶段,测试完一切ok后,准备打包以及提交,不料看到网上众教程,好多 ...
- (转载)Total Commander 常用快捷键(并附快捷键大全)
(转载)http://blog.chinaunix.net/uid-532511-id-3051990.html Total Commander 常用快捷键 喜欢用Total Commander的人, ...
- (转载)JS事件监听 JS:attachEvent和addEventListener使用方法
(转载)http://www.chhua.com/web-note146 attachEvent和addEventListener使用方法 Js代码 <html> <head> ...
- HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)
Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...
- HDU 1078 FatMouse and Cheese (记忆化搜索+dp)
详见代码 #include <iostream> #include <cstdio> #include <cstdlib> #include <memory. ...
- phonegap与微信开放平台接口整合
在开发phonegap应用的过程中有个需求需要将应用的消息推送到微信上.于是我自己写了一个微信的phonegap插件,并成功整合进了应用. 插件地址:https://github.com/ajccom ...