hdoj 1015 Safecracker
来源:互联网 发布:mac安装win10镜像 编辑:程序博客网 时间:2024/05/30 23:03
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)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题意:要打开安全锁
密码 由 一个数字 和 一个字符串组成
从给定字符中找 5 个字符 v, w, x, y, z 满足 v - w^2 + x^3 - y^4 + z^5 (A=1, B=2, …, Z=26).例如 :
输入 1 ABCDEFGHIJKL
由于 6 - 9^2 + 5^3 - 3^4 + 2^5 = 1
输出 LKEBA# include<stdio.h># include<string.h># include<algorithm>using namespace std;char a[6],b[15];int v[15],m,k,len;bool cmp(char a,char b){return a>b;} int W(char a,int k){ int c1=1; for(int i=1;i<=k;i++) c1=c1*(a+1-'A');return c1;}void dfs(int n){if(n==5){int sum=W(a[0],1)-W(a[1],2)+W(a[2],3)-W(a[3],4)+W(a[4],5); if(sum==m){for(int i=0;i<5;i++)printf("%c",a[i]);printf("\n");k=1;}return ;}for(int i=0;i<len;i++){if(!v[i]){v[i]=1; a[n]=b[i];dfs(n+1);//遍历 if(k) return ;//如果得到结果结束遍历 v[i]=0;}}}int main(){while(~scanf("%d %s",&m,&b)&&!((m==0)&&(strcmp(b, "END")==0))){len=strlen(b);sort(b,b+len,cmp); //将字符串的元素从大到小排列 memset(v,0,sizeof(v)); k=0; //判断是否有解 dfs(0);if(!k)printf("no solution\n");}return 0;}
阅读全文
0 0
- HDOJ 1015 Safecracker
- HDOJ 1015 Safecracker
- hdu/hdoj 1015 Safecracker
- HDOJ 1015 Safecracker
- HDOJ 1015 Safecracker
- hdoj 1015 Safecracker 【dfs】
- hdoj 1015 Safecracker
- HDOJ 1015 Safecracker-DFS
- hdoj 1015 Safecracker【DFS】
- hdoj 1015 Safecracker 【DFS】
- HDOJ-1015Safecracker(DFS)
- HDOJ HDU 1015 Safecracker
- hdoj 1015 Safecracker
- HDOJ 1015 Safecracker
- HDOJ 1015 Safecracker 简单搜索
- hdoj 1015 Safecracker---盗窃贼
- HDOJ 1015 Safecracker(DFS)
- HDOJ/HDU 1015 Safecracker(深搜)
- CentOS通过yum安装Mariadb(MySQL)无法启动服务或者找不到mysql.sock(2)
- 文章标题
- CPP
- poi 导入Excel封装 并处理数据类型
- 51nod 1213 二维曼哈顿距离最小生成树
- hdoj 1015 Safecracker
- 将自己已有的github库迁移到ubuntu系统下
- [CDN 技术] HTTP参数中Etag的重要性
- Bone Collector -简单01背包
- 一次应用访问数据库 IP 配成外网 IP 引发的血案
- [已解决]Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()'
- 约瑟夫环,数三退一类问题(数组解法)
- Ubuntu下搭建VPN服务器的方法
- ACM复习(9)8611 大牛之路I