杭电1015 Safecracker 暴力
来源:互联网 发布:网络道德问题调查报告 编辑:程序博客网 时间:2024/05/23 11:42
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10937 Accepted Submission(s): 5608
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."
"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 ABCDEFGHIJKL11700519 ZAYEXIWOVU3072997 SOUGHT1234567 THEQUICKFROG0 END
Sample Output
LKEBAYOXUZGHOSTno solution
Source
Mid-Central USA 2002
Recommend
JGShining | We have carefully selected several similar problems for you: 1239 1238 1072 1240 1372
第一次写出来这么丑的代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespace std;int i,j,k,l,m,n,num1,num2,num3,num4,num5,help,ans,flag;char s[1100],v,w,x,y,z;struct node{char s[1100];}t[11000];int cmp(node a,node b){return strcmp(a.s,b.s)>0;}int main(){while(scanf("%d%s",&ans,s),strcmp(s,"END\0")){l=strlen(s);flag=0;for(i=0;i<l;i++){num1=s[i]-'A'+1;for(j=0;j<l;j++){num2=s[j]-'A'+1;if(i==j)continue;for(k=0;k<l;k++){num3=s[k]-'A'+1;if(k==i||k==j)continue;for(m=0;m<l;m++){num4=s[m]-'A'+1;if(m==i||m==j||m==k)continue;for(n=0;n<l;n++){num5=s[n]-'A'+1;if(n==m||n==i||n==j||n==k)continue;if((num1-pow(num2,2)+pow(num3,3)-pow(num4,4)+pow(num5,5))==ans){t[flag].s[0]=s[i];t[flag].s[1]=s[j];t[flag].s[2]=s[k];t[flag].s[3]=s[m];t[flag].s[4]=s[n];t[flag].s[6]='\0';flag++;}}}}}}sort(t,t+flag,cmp);if(flag)printf("%s\n",t[0].s);elseprintf("no solution\n");}}
0 0
- 杭电1015 Safecracker 暴力
- 杭电 1015 Safecracker
- 杭电 1015 Safecracker
- 杭电 1015 Safecracker
- 杭电 ACM 1015 --Safecracker
- 杭电OJ 1015 Safecracker
- hdu 1015 Safecracker 暴力
- 杭电-1015Safecracker(DFS)
- hdu 1015 Safecracker 暴力dfs
- HDU 1015 Safecracker (暴力枚举)
- 杭电 HDU ACM 1015 Safecracker (dfs 枚举排列)
- HDU ACM 1015 Safecracker 暴力DFS
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
- hdoj 1015 safecracker(暴力枚举)
- 杭电1796 Safecracker(DFS)
- 杭电ACM1015——Safecracker
- POJ1248 Safecracker 暴力
- Safecracker(暴力)
- Linux常用命令大全
- 2015书单
- 关于脚本log返回乱码解决方法
- UVA 11090Going in Cycle!! (spfa + 二分)
- 分布式视频分享网站
- 杭电1015 Safecracker 暴力
- LinkedHashMap和HashMap的区别以及使用方法
- Android 解析xml的三种方式
- MDX 中 drilldownmember函数的理解和用法
- NFS文件系统搭建
- Fragment中获取Activity的Context
- Loadrunner 接口测试的两种方法
- 如何查看python selenium的api
- iOS 保持界面流畅的技巧