HD problem
来源:互联网 发布:敬请悉知 编辑:程序博客网 时间:2024/05/16 02:03
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5175 Accepted Submission(s): 2598
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
分析:
用暴力破解法
代码:
#include <stdio.h>long double f(long double ch,int n){ ch=ch-'A'+1;n--; int ch1=ch; for(int i=0;i<n;i++) ch*=ch1; return ch;}int main(){ int star=0; int key; while(true) { scanf("%d",&key); char ch [30],num[6]={0};num[5]='\0'; scanf("%s",ch); if(key==0) return 0; for(;ch[star]!='\0';star++);star--; for(int i=star;i>=0;i--) for(int j=star;j>=0;j--) if(j!=i) for(int k=star;k>=0;k--) if(k!=i&&k!=j) for(int l=star;l>=0;l--) if(l!=i&&l!=j&&l!=k) for(int m=star;m>=0;m--) if(m!=i&&m!=j&&m!=k&&m!=l) { bool judger=false; if(key==f(ch[m],1)-f(ch[l],2)+f(ch[k],3)-f(ch[j],4)+f(ch[i],5)) { if(ch[m]==num[0]) { if(ch[l]==num[1]) { if(ch[k]==num[2]) { if(ch[j]==num[3]) { if (ch[i]>num[4]) judger=1; }else if(ch[j]>num[3])judger=1; }else if(ch[k]>num[2])judger=1; }else if(ch[l]>num[1])judger=1; }else if(ch[m]>num[0])judger=true; if(judger) { num[0]=ch[m];num[1]=ch[l];num[2]=ch[k];num[3]=ch[j];num[4]=ch[i]; } } } bool j=false; for(int i=0;i<5;i++) if(num[i]!=0) j=true; if(j) printf("%s\n",num); else { printf("no solution\n"); } } return 0;}
Run IDSubmit TimeJudge StatusPro.IDExe.TimeExe.MemoryCode Len.LanguageAuthor75481212013-01-26 00:07:43Accepted101515MS376K1512 BG++jimzhai75480202013-01-25 23:35:14Accepted101531MS356K1207 BG++jimzhai
- HD problem
- HD 1001 sum problem
- HD 1001 sum problem
- 1407231857-hd-Problem A .cpp
- 1407231901-hd-Problem C.cpp
- 1407231910-hd-Problem E.cpp
- 1407231927-hd-Problem F.cpp
- 1407231932-hd-Problem H.cpp
- 1407231940-hd-Problem B.cpp
- 1407232100-hd-Problem G.cpp
- hd 2055 An easy problem
- hd 2123 An easy problem
- hd-1000-A + B Problem
- HD OJ 1002Problem 大数相加
- 1407260834-hd-An easy problem.cpp
- 1407301031-hd-A + B Problem II.cpp
- hd 1048 The Hardest Problem Ever
- 1409061046-hd-The 3n + 1 problem
- thinkphp中模版引擎中常用的变量输出
- 搭建strus2 + spring + hibernate (三)spring管理hibernate SessionFactory 篇
- hive中使用自定义函数(UDF)实现分析函数row_number的功能
- Ubuntu中SSH命令详解
- 多态
- HD problem
- 微薄推广测试
- 运维故障
- VxWorks驱动程序开发指南(四)--驱动程序的组织结构
- Proxy SwitchySharp地址
- spring管理hibernate数据库连接(1)
- 好玩的ios APP动动手指,轻松挣美金~~
- poj 1125 -- Stockbroker Grapevine (最短路)
- HIVE Row_Sequence 实现列自增长