解题思路:这题相当诡异,样例没过,交了,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的更多相关文章

  1. HDOJ(HDU).1015 Safecracker (DFS)

    HDOJ(HDU).1015 Safecracker [从零开始DFS(2)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1 ...

  2. hdu 1015 Safecracker 水题一枚

    题目链接:HDU - 1015 === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Klein s ...

  3. ZOJ 1403&&HDU 1015 Safecracker【暴力】

    Safecracker Time Limit: 2 Seconds      Memory Limit: 65536 KB === Op tech briefing, 2002/11/02 06:42 ...

  4. HDU 1015 Safecracker【数值型DFS】

    Safecracker Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. HDU 1015 Safecracker(第一次用了搜索去遍历超时,第二次用for循环能够了,思路一样的)

    Safecracker Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total S ...

  6. HDU 1015.Safecracker【暴力枚举】【8月17】

    Safecracker Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is lo ...

  7. HDOJ/HDU 1015 Safecracker(深搜)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  8. HDOJ/HDU 1015 Safecracker(枚举、暴力)

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kle ...

  9. HDU 1015 Safecracker 解决问题的方法

    Problem Description === Op tech briefing, 2002/11/02 06:42 CST ===  "The item is locked in a Kl ...

随机推荐

  1. POJ 1419

    #include <iostream> #define MAXN 105 #define max _max using namespace std; int j; bool _m[MAXN ...

  2. Linux多线程之同步2 —— 生产者消费者模型

    思路 生产者和消费者(互斥与同步).资源用队列模拟(要上锁,一个时间只能有一个线程操作队列). m个生产者.拿到锁,且产品不满,才能生产.当产品满,则等待,等待消费者唤醒.当产品由空到不空,通知消费者 ...

  3. MVC中前台如何向后台传递数据------$.get(),$post(),$ajax(),$.getJSON()总结

    一.引言 MVC中view向controller传递数据的时候真心是一个挺让人头疼的一件事情.因为原理不是很懂只看一写Dome,按葫芦画瓢只能理解三分吧. 二.解读Jquery个Ajax函数 $.ge ...

  4. Shell练习 验证号码

    原文: https://leetcode.com/problems/valid-phone-numbers/ Given a text file file.txt that contains list ...

  5. 【PSR规范专题(3)】PSR-2 代码风格规范

    [PSR规范专题(3)]PSR-2 代码风格规范 标签(空格分隔): PHP 转载自:https://github.com/PizzaLiu/PHP-FIG/blob/master/PSR-2-cod ...

  6. iOS开发--动画(Animation)总结

    UIView的,翻转.旋转,偏移,翻页,缩放,取反的动画效果   翻转的动画 //开始动画 [UIView beginAnimations:@"doflip" context:ni ...

  7. iOS开发日期处理

    Foundation框架之 日期与时间 #import"ViewController.h"@interfaceViewController() { NSTimer*_timer;/ ...

  8. iOS开发推送--客户端 服务端

    1.推送过程简介 (1)App启动过程中,使用UIApplication::registerForRemoteNotificationTypes函数与苹果的APNS服务器通信,发出注册远程推送的申请. ...

  9. iOS sqlite3数据库解析

    看来从版本3.3.1基本上已经支持线程句柄的传递功能.具体限制我标记了一下.(6) Is SQLite threadsafe?SQLite is threadsafe. We make this co ...

  10. Android 设置闹铃步骤和基础代码

    主要分三步: 1. 设置闹铃时间; 2. 接收闹铃事件广播; 3. 重开机后重新计算并设置闹铃时间;   1. 设置闹铃时间(毫秒) private void setAlarmTime(Context ...