Safecracker
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 2178 | Accepted: 1231 |
Description
"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 - w2 + x3 - y4 + z5 = target
"For example, given target 1 and letter set ABCDEFGHIJKL, one possible solution is FIECB, since 6 - 92 + 53 - 34 + 25 = 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."
"Develop a program to find Klein combinations in preparation for field deployment. Use standard test methodology as per departmental regulations.
v - w2 + x3 - y4 + z5 = target
"For example, given target 1 and letter set ABCDEFGHIJKL, one possible solution is FIECB, since 6 - 92 + 53 - 34 + 25 = 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."
"Develop a program to find Klein combinations in preparation for field deployment. Use standard test methodology as per departmental regulations.
Input
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.
Output
For each line output the unique Klein combination, 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 //这组数据有问题,我的程序的结果是"no solution"(已Ac) GHOST no solution 题目大意:A,B,C,D......Z这26个大写字母的值依次为1,2,3.......26.给你个数target和可选字符表,在表中找5个字符,是否满足v - w2 + x3 - y4 + z5 = target, 若没有,则输出no solution,否则按照最大字典序输出5个字符。注:最大字典序:先排大的,然后才是小的(从小到大严格递减),例如a,d,c,z,h的最大字典序为 z,h,d,c,a 思路:先将可选字符串集合按照从大到小的方式排序,然后就是5重循环依次判断,若找到,输出并立刻跳出 代码:/* @author : liuwen */ #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <cstdlib> #include <queue> #include <stack> #include <map> #include <vector> #include <cmath> using namespace std; bool cmp(const char &a,const char &b){ return a>b; } int fun(int v,int w,int x,int y,int z) { return v - pow(w*1.0,2.0) + pow(x*1.0,3.0) - pow(y*1.0,4.0) + pow(z*1.0,5.0); } int main() { //freopen("in.txt","r",stdin); int a,b,c,d,e,target; char src[50]; while(scanf("%d%s",&target,src)==2){ if(target==0&&strcmp(src,"END")==0) break; int len=strlen(src); sort(src,src+len,cmp);//从大到小排序 bool isFind=false; for(a=0;a<len;a++){ for(b=0;b<len;b++) if(b!=a){ for(c=0;c<len;c++) if(c!=b&&c!=a){ for(d=0;d<len;d++) if(d!=c&&d!=b&&d!=a){ for(e=0;e<len;e++)if(e!=d&&e!=c&&e!=b&&e!=a){ if(fun(src[a]-'A'+1,src[b]-'A'+1,src[c]-'A'+1,src[d]-'A'+1,src[e]-'A'+1)==target){ isFind=true; break; } if(isFind) break; } if(isFind) break; } if(isFind) break; } if(isFind) break; } if(isFind) break; } if(!isFind) printf("no solution\n"); else{ printf("%c%c%c%c%c\n",src[a],src[b],src[c],src[d],src[e]); } } return 0; }

本文介绍了一种独特的Kleins保险箱解锁挑战,玩家需要根据保险箱门上的铭文和数字线索找到正确的字母组合来打开保险箱。文章详细解释了如何通过数学公式计算出特定的字母组合,并提供了一个示例程序来解决这个问题。
407

被折叠的 条评论
为什么被折叠?



