ZOJ1403 Safecracker

Safecracker

Time Limit: 2 Seconds      Memory Limit: 65536 KB

=== 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."


Sample Input

1 ABCDEFGHIJKL
11700519 ZAYEXIWOVU
3072997 SOUGHT
1234567 THEQUICKFROG
0 END


Sample Output

LKEBA
YOXUZ
GHOST
no solution

题意简述:

        密码序列由一系列大写字母组成,在解密序列不唯一的情况下,按字典序输出最后一个,解密公式:v - w^2 + x^3 - y^4 + z^5 = target 

解题思路:
       这是一道典型的枚举题。题目中,解的值域已经确定,解元素中的v,w,x,y,z都是题目中给定集合中的一个元素。尽管枚举法的算法复杂度是指数级的,但鉴于给定集合最多只有12个元素,完全可以直接用枚举法。另外,题目中约束条件,v、w、x、y、z各不相同,明显不属于解集的元素可以很容易的通过判断来排除。需要注意的是,题目求的密码序列是按字典序输出最后一个,所以需要事先将集合元素排好序。

       加油!!2018/4/40


#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
char letters[15];
int value[15],target;

void solve(int len){
	int a,b,c,d,e;
	for(a = 0;a < len;a++){
		for(b = 0;b < len;b++){
			if(a!=b){
				for(c = 0;c < len;c++){
					if(a!=c&&b!=c){
						for(d = 0;d < len;d++){
							if(a!=d&&b!=d&&c!=d){
								for(e = 0;e < len;e++){
									if(a!=e&&b!=e&&c!=e&&d!=e){
										if(value[a]-pow(value[b],2.0)+pow(value[c],3.0)-pow(value[d],4.0)+pow(value[e],5.0)==target){
											printf("%c%c%c%c%c\n",value[a]+'A'-1,value[b]+'A'-1,value[c]+'A'-1,value[d]+'A'-1,value[e]+'A'-1);
											return ;
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	printf("no solution\n");
} 
bool compare(int a,int b){
	return a > b;     //降序排列 
}
int main(){
	int i;
	while(scanf("%d %s",&target,letters)!=EOF){
		memset(value,0,sizeof(value));
		if(target==0&&strcmp(letters,"END")==0){
			break;
		}
		i = 0;
		while(letters[i]){
			value[i] = letters[i]-'A'+1;
			i++;
		}
		sort(value,value+i,compare);
	    solve(i);
	} 
	
	
 return 0;
}

基于SSM框架的智能家政保洁预约系统,是一个旨在提高家政保洁服务预约效率和管理水平的平台。该系统通过集成现代信息技术,为家政公司、家政服务人员和消费者提供了一个便捷的在线预约和管理系统。 系统的主要功能包括: 1. **用户管理**:允许消费者注册、登录,并管理他们的个人资料和预约历史。 2. **家政人员管理**:家政服务人员可以注册并更新自己的个人信息、服务类别和服务时间。 3. **服务预约**:消费者可以浏览不同的家政服务选项,选择合适的服务人员,并在线预约服务。 4. **订单管理**:系统支持订单的创建、跟踪和管理,包括订单的确认、完成和评价。 5. **评价系统**:消费者可以在家政服务完成后对服务进行评价,帮助提高服务质量和透明度。 6. **后台管理**:管理员可以管理用户、家政人员信息、服务类别、预约订单以及处理用户反馈。 系统采用Java语言开发,使用MySQL数据库进行数据存储,通过B/S架构实现用户与服务的在线交互。系统设计考虑了不同用户角色的需求,包括管理员、家政服务人员和普通用户,每个角色都有相应的权限和功能。此外,系统还采用了软件组件化、精化体系结构、分离逻辑和数据等方法,以便于未来的系统升级和维护。 智能家政保洁预约系统通过提供一个集中的平台,不仅方便了消费者的预约和管理,也为家政服务人员提供了一个展示和推广自己服务的机会。同时,系统的后台管理功能为家政公司提供了强大的数据支持和决策辅助,有助于提高服务质量和管理效率。该系统的设计与实现,标志着家政保洁服务向现代化和网络化的转型,为管理决策和控制提供保障,是行业发展中的重要里程碑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值