HDU 1015 Safecracker
解题思路:这题相当诡异,样例没过,交了,A了,呵呵,因为理论上是可以通过的,所以
我交了一发,然后就神奇的过了。首先要看懂题目。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = ;
int vis[maxn], A[maxn], flag, len, sum, p[maxn], n;
char str[maxn]; int cmp(int x, int y)
{
return x > y;
} void DFS(int cnt)
{
if(cnt == )
{
sum = pow(p[], ) - pow(p[],) + pow(p[],) - pow(p[],) + pow(p[],);
if(sum == n) flag = ; //搜到符合条件的就跳出。
return ;
} for(int i = ; i < len; i++)
{
//每个点有选和不选两种情况,所以很自然想到回溯。
if(!vis[i])
{
p[cnt] = A[i];//存储路径
vis[i] = ;
DFS(cnt + );
vis[i] = ;
}
if(flag) return ; //这一步必不可少,表明搜到符合条件的就要立即跳出。
}
return ;
} int main()
{
while(~scanf("%d", &n))
{
memset(vis, , sizeof(vis));
scanf("%s", str);
if(strcmp(str, "END") == ) break;
len = strlen(str);
for(int i = ; i < len; i++) A[i] = str[i] - 'A' + ;
sort(A, A + len, cmp); //直接从大到下排序,搜到第一个符合条件的直接跳出。 flag = ;
DFS();
//flag等于1表示搜到了
if(flag) for(int i = ; i < ; i++) printf("%c", p[i] + );
else printf("no solution");
printf("\n");
}
return ;
}
HDU 1015 Safecracker的更多相关文章
- HDOJ(HDU).1015 Safecracker (DFS)
HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...
- hdu 1015 Safecracker 水题一枚
题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...
- ZOJ 1403&&HDU 1015 Safecracker【暴力】
Safecracker Time Limit: 2 Seconds Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 ...
- HDU 1015 Safecracker【数值型DFS】
Safecracker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1015 Safecracker(第一次用了搜索去遍历超时,第二次用for循环能够了,思路一样的)
Safecracker Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total S ...
- HDU 1015.Safecracker【暴力枚举】【8月17】
Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is lo ...
- HDOJ/HDU 1015 Safecracker(深搜)
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
- HDOJ/HDU 1015 Safecracker(枚举、暴力)
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...
- HDU 1015 Safecracker 解决问题的方法
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kl ...
随机推荐
- 动态调用wcf接口服务
1.url:http://localhost:8002/名称.svc/basic(.svc结尾) 2.需要引用的命名空间System.ServiceModel 3.调用代码: public class ...
- $headers = $this->input->request_headers();返回请求头(header)数组
请查看:CI中的输入类部分 建议用第一个 $headers = $this->input->request_headers() $this->input->request_he ...
- 15.RDD 创建内幕解析
第15课:RDD创建内幕 RDD的创建方式 Spark应用程序运行过程中,第一个RDD代表了Spark应用程序输入数据的来源,之后通过Trasformation来对RDD进行各种算子的转换,来实现具体 ...
- C#中out的用法
out的用法 out 关键字会导致参数通过引用来传递.这与 ref 关键字类似,不同之处在于 ref 要求变量必须在传递之前进行初始化.若要使用 out 参数,方法定义和调用方法都必须显式使用 out ...
- odata
http://www.odata.org/ Open Data Protocol (开放数据协议,OData)是用来查询和更新数据的一种Web协议,其提供了把存在于应用程序中的数据暴露出来的方式.OD ...
- QT 多线程程序设计
参考:http://www.cnblogs.com/hicjiajia/archive/2011/02/03/1948943.html http://mobile.51cto.com/symbian- ...
- 把Message转换成String
把Message转换成String注意,这里欠缺CM消息和CN消息,因为它们不是系统消息,不经过Dispatch API转发,但是可以把它们写在WndProc里,这样SendMessage送来的消息也 ...
- fastdfs-client-java工具类封装
FastDFS是通过StorageClient来执行上传操作的 通过看源码我们知道,FastDFS有两个StorageClient工具类.
- SSIS ->> Reliability And Scalability
Error outputs can obviously be used to improve reliability, but they also have an important part to ...
- lua简化cocos2dx的Action动画序列
情景 今天写代码时,又要写一个很常见的动画,就是变大变小模拟那个弹性的赶脚,很常用但写起来挺麻烦,封装一下用起来就简单多了. 当然我也知道有缓动动画(EaseAction)可以实现反弹效果,但这不是重 ...