开闸。放水!!hdu 1015
来源:互联网 发布:mysql配置文件在哪 编辑:程序博客网 时间:2024/04/28 15:46
Safecracker
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4398 Accepted Submission(s): 2221
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
#include <iostream>#include <algorithm>#include <string>using namespace std;bool eq(int v, int w, int x, int y, int z, int t){if (v - w*w + x*x*x - y*y*y*y +z*z*z*z*z == t)return true;return false;}bool cmp(char a, char b){return a>b;}int main(){int i, j, k, l, m, f, len, t;string st;while (cin>>t>>st, t, st!="END"){f = 0;sort(st.begin(), st.end(), cmp);len = st.length();for (i=0;i<len && !f;++i) for (j=0;j<len && !f;++j) {if (i==j) continue;for (k=0;k<len && !f;++k){if (k==i || k==j) continue;for (l=0;l<len && !f;++l){if(l==i || l==j || l==k) continue;for (m=0;m<len && !f;++m){if (m==i || m==j || m==k || m==l) continue;if (eq(st[i]-'A'+1,st[j]-'A'+1,st[k]-'A'+1,st[l]-'A'+1,st[m]-'A'+1,t)){cout<<st[i]<<st[j]<<st[k]<<st[l]<<st[m]<<endl;f = 1;break;}}}}}if (!f) printf("no solution\n");}return 0;}
- 开闸。放水!!hdu 1015
- 第五招: 洞悉“开闸放水”的玄机
- 德国逼平国足是放水吗?
- 放水电费水电费
- IPO开闸 刺激资金流向创投
- 关于IPO开闸与加息的问题
- 为放水电费等是
- 中国香港放水,中国也无缘世界杯
- 风景好的手机号放水电费
- 一篇小程序的放水的文章
- 全球央妈大放水,如何守住财富!
- 同学们如开闸的洪水跑了出去
- 昨天晚上看了一场经典的放水大战
- “放水养鱼”时代终结 八部委促电子商务规范化
- 银行钱荒央行拒“放水” 李克强总理一句话定调
- 然风格更好的股份三分店十多个放水电费
- 放水电费水电费水电费说的发送到发送到
- 2011.12.1央行下调存款准备金,放水4千亿RMB解读
- cron表达式(quartz中时间表达式)
- STL之Deque双端队列
- SQL Server中的SELECT 语句
- STL学习笔记之 (四)容器 list
- Clear Case V7.0 官网下载地址
- 开闸。放水!!hdu 1015
- 集群计算
- HDU 1018 阶乘的位数 stirling公式
- 拿下AJAX(一)——AJAX初体验
- hdu 4192 #模拟计算+全排列
- 链表中随机取出k个数 - 蓄水池抽样
- 黑马程序员_day02 语句。
- 输入校验的流程
- Tomcat version 6.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5 Web modules