HDU 1015 Safecracker
来源:互联网 发布:金鑫松 知乎 编辑:程序博客网 时间:2024/06/03 05:46
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
又是一道水题,就是找满足v - w^2 + x^3 - y^4 + z^5 = target条件的5个字母,我用的5层循环过了。放代码:
#include<iostream>#include<string.h>#include<algorithm>using namespace std;bool compare(int a,int b){return a>b;}int main(){char password[13];int target,lenth,i,j,k,l,m,flag;int a[12];//用a记录值while(cin>>target>>password){if(target==0 && password[0]=='E' && password[1]=='N' && password[2]=='D' && password[3]=='\0')break;lenth=strlen(password);for(i=0;i<lenth;i++)a[i]=password[i]-'A'+1;sort(a,a+lenth,compare);sort(password,password+lenth,compare);flag=0;for(i=0;i<lenth;i++){for(j=0;j<lenth;j++){if(i==j)continue;for(k=0;k<lenth;k++){if(i==k || j==k)continue;for(l=0;l<lenth;l++){if(i==l ||j==l ||k==l)continue;//如果有重复就跳for(m=0;m <lenth;m++){if(i==m||j==m||k==m||l==m)continue;if(a[i]-a[j]*a[j]+a[k]*a[k]*a[k]-a[l]*a[l]*a[l]*a[l]+a[m]*a[m]*a[m]*a[m]*a[m]==target){cout<<password[i]<<password[j]<<password[k]<<password[l]<<password[m]<<endl;flag=1;break;}}if(flag==1)break;}if(flag==1)break;}if(flag==1)break;}if(flag==1)break;}if(flag==0)cout<<"no solution"<<endl;}return 0;}
0 0
- HDU - 1015 Safecracker
- HDU 1015 Safecracker
- HDU 1015 Safecracker
- Hdu 1015 Safecracker
- hdu 1015 Safecracker
- hdu 1015 Safecracker(枚举)
- hdu 1015 Safecracker
- hdu 1015 Safecracker
- HDU 1015 Safecracker(深搜)
- hdu 1015 Safecracker
- hdu 1015 Safecracker dfs()
- hdu 1015 Safecracker
- HDU 1015 Safecracker
- hdu(1015)Safecracker
- hdu/hdoj 1015 Safecracker
- hdu 1015 Safecracker
- hdu 1015 Safecracker
- hdu 1015 Safecracker
- 15-《电子入门趣谈》第三章_电子世界中的五官---传感器-3.1传感器概述
- Android 自动建表
- 所有图片的uri形式
- 搜索布局(Search Layouts)
- 【转载】人脸检测
- HDU 1015 Safecracker
- [javase学习笔记]-8.2 成员变量与静态变量的区别
- 组合游戏
- Android surfaceview详解(一)
- 非正式协议
- maven项目如何生成war文件
- Android 快速开发系列 打造万能的ListView GridView 适配器
- VTK基础概念
- 升级Android Studio到2.0 preview导致的 java.lang.VerifyError错误