HDU 1015 Safecracker (暴力枚举)
来源:互联网 发布:银行家算法 0 4 2 0 编辑:程序博客网 时间:2024/05/16 19:50
=== 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."
"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."
1 ABCDEFGHIJKL11700519 ZAYEXIWOVU3072997 SOUGHT1234567 THEQUICKFROG0 END
LKEBAYOXUZGHOSTno solution
1 ABCDEFGHIJKL11700519 ZAYEXIWOVU3072997 SOUGHT1234567 THEQUICKFROG0 END
LKEBAYOXUZGHOSTno solution
#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>using namespace std;int main(){int target;char a[13];while(~scanf("%d%s",&target,a)){if(target==0&&a[0]=='E'&&a[1]=='N'&&a[2]=='D')break;int b[13];int len=strlen(a);for(int i=0;i<len;i++){b[i]=a[i]-'A'+1;}sort(b,b+len);int flag=0;for(int i=len-1;i>=0;i--){for(int i1=len-1;i1>=0;i1--){if(b[i]==b[i1])continue;for(int i2=len-1;i2>=0;i2--){if(b[i2]==b[i]||b[i2]==b[i1])continue;for(int i3=len-1;i3>=0;i3--){if(b[i3]==b[i2]||b[i3]==b[i1]||b[i3]==b[i])continue;for(int i4=len-1;i4>=0;i4--){if(b[i4]==b[i]||b[i4]==b[i1]||b[i4]==b[i2]||b[i4]==b[i3])continue;if((b[i]-b[i1]*b[i1]+b[i2]*b[i2]*b[i2]-b[i3]*b[i3]*b[i3]*b[i3]+b[i4]*b[i4]*b[i4]*b[i4]*b[i4])==target){printf("%c%c%c%c%c\n",b[i]+'A'-1,b[i1]+'A'-1,b[i2]+'A'-1,b[i3]+'A'-1,b[i4]+'A'-1);flag=1;}if(flag)break;}if(flag)break;}if(flag)break;}if(flag)break;}if(flag)break;}if(!flag)cout<<"no solution"<<endl;}return 0;}
阅读全文
0 0
- HDU 1015 Safecracker (暴力枚举)
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
- hdu 1015 Safecracker 暴力
- hdu 1015 Safecracker(枚举)
- hdu 1015 Safecracker 枚举
- hdu 1015 Safecracker 枚举
- hdu 1015 Safecracker 暴力dfs
- hdoj 1015 safecracker(暴力枚举)
- hdu1015 Safecracker (暴力枚举)
- Safecracker(枚举暴力)
- HDU 1015.Safecracker【暴力枚举】【8月17】
- HDU ACM 1015 Safecracker 暴力DFS
- poj 1248 Safecracker(暴力枚举)
- Safecracker--简单暴力枚举(Problem ID:1015)
- hdu 1015 Safecracker(暴力枚举,注意它要求按字典序最大的,所以开始要排序)
- HDU-1015/暴力枚举
- HDU-1015-Safecracker(Java && 暴力大法好 && 简单字典序)
- HDU-1015 Safecracker(DFS+暴力回溯 / 五重循环)
- 8月20号 XML写入
- VS Code 快捷键(中英文对照)
- ArcGIS API for JavaScript实现地图双屏联动
- Android studio 项目构建二|优化编译速度(2)
- QT signals and slots
- HDU 1015 Safecracker (暴力枚举)
- Navicat For Mysql快捷键
- js原生图片轮播
- 静态缓存和动态缓存的比较
- Hexo+GitHubPage搭建博客
- hts engine语音识别
- Linux下MD5移植和编程
- 1.2数据结构的历史和在计算机学科中的地位
- Android实现自定义Toast,并且防止重复显示