Safecracker

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
 
 
分析:因为最多只有12个字母,所以几个for循环暴力找就行了,注意要按字典序大的输出,还有几个小优化。
 
 #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(暴力)的更多相关文章

  1. hdu 1015 Safecracker 水题一枚

    题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...

  2. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  3. HDU 1015.Safecracker【暴力枚举】【8月17】

    Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is lo ...

  4. HDOJ/HDU 1015 Safecracker(枚举、暴力)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  5. ZOJ 1403&&HDU 1015 Safecracker【暴力】

    Safecracker Time Limit: 2 Seconds      Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 ...

  6. HDU 6351暴力枚举 6354计算几何

    Beautiful Now Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)T ...

  7. HDU 5944 暴力

    Fxx and string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)T ...

  8. hdu 4039 暴力

    思路:用map将每个字符串与一个数字进行对应,然后暴力统计就好了 #include<cstring> #include<iostream> #include<cstdio ...

  9. HDU 1015 Safecracker 解决问题的方法

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is locked in a Kl ...

  10. 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 递推到下一个 ...

随机推荐

  1. iframe的安全问题

    今天尝试在iframe中嵌入外部网站, 碰到了一些小问题. 如何让自己的网站不被其他网站的iframe引用? 我测试的时候发现我把iframe的src指定到github不起作用. 原来是它把X-Fra ...

  2. git使用的常见命令(一)

    .查看当前有哪些branch git branch 其中有*选中的分支是你的当前使用的分支 .新建一个分支 git branch dev_xiaoming .切换到一个分支 git checkout ...

  3. struts2结合生成验证码

    import java.util.Arrays; /** * 工具类,生成随机验证码字符串 * @version 1.0 2012/12/01 * @author shiyz * */ public ...

  4. linux VM命令下查找

    使用vi编辑器编辑长文件时,常常是头昏眼花,也找不到需要更改的内容. 这时,使用查找功能尤为重要. 方法如下: 1.命令模式下输入“/字符串”,例如“/Section 3”. 2.如果查找下一个,按“ ...

  5. FindBugs

    FindBugs是一个能静态分析源代码中可能会出现Bug的Eclipse插件工具. 可以从http://sourceforge.net/project/showfiles.php?group_id=9 ...

  6. HDU 5969 最大的位或 【贪心】 (2016年中国大学生程序设计竞赛(合肥))

    最大的位或 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem De ...

  7. [转]NHibernate之旅(3):探索查询之NHibernate查询语言(HQL)

    本节内容 NHibernate中的查询方法 NHibernate查询语言(HQL) 1.from子句 2.select子句 3.where子句 4.order by子句 5.group by子句 实例 ...

  8. html页面显示div源代码:用<xmp></xmp>标签

    html页面显示div源代码:用<xmp></xmp>标签效果还可以.

  9. c#自动更新+安装程序的制作

    一.自动更新的实现 让客户端实现自动更新,通常做法是在客户端部署一个单独的自动更新程序.主程序启动后,访问服务端,检查配置文件是否有更新版本,有更新版本就启动更新程序,由更新负责下载更新版本,并更新客 ...

  10. 转 wordpress搭建

    新建一个博客文件 在搭建博客的过程中,我们需要创建一个文件,用来存储博客的相关信息.这些信息包括域名的信息,主机空间服务器ip,FTP登录名和密码,空间面板登录信息等等,只要是与该博客有关的信息,全部 ...