hdu1015

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int cmp(void* a, void* b)
{
return *((char*)a)-*((char*)b);
}

void solve(int t, char* dic)
{
int v,w,x,y,z,l;
int p[12];
l = strlen(dic);
qsort((void*)dic,l,sizeof(char),cmp);
for(v=0;v<l;v++)
{
p[v]=dic[v]-‘A‘+1;
}

for(v=l-1;v>=0;v--)
for(w=l-1;w>=0;w--)
for(x=l-1;x>=0;x--)
for(y=l-1;y>=0;y--)
for(z=l-1;z>=0;z--)
{
if(w==v)continue;
if(x==w||x==v)continue;
if(y==x||y==w||y==v)continue;
if(z==y||z==x||z==w||z==v)continue;
if(p[v]-p[w]*p[w]+p[x]*p[x]*p[x]-p[y]*p[y]*p[y]*p[y]+p[z]*p[z]*p[z]*p[z]*p[z] == t)
{
printf("%c%c%c%c%c\n",dic[v],dic[w],dic[x],dic[y],dic[z]);
return;
}
}
printf("no solution\n");
}
int main(void)
{
int t;
char dic[13];
while(scanf("%d %s",&t,dic)!=EOF)
{
if(!t && !strcmp(dic,"END"))break;
solve(t,dic);
}
return 0;
}

时间: 2024-08-05 02:33:43

hdu1015的相关文章

HDU-1015 Safecracker(暴力枚举)

题目回顾(HDU-1015) Safecracker Problem Description "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. Fortunat

hdu1015 dfs暴力搜索所有情况模板

脑子有点坑,不知道为什么,可能以前遇到阴影了,现在看到dfs暴力搜有种莫名的害怕,总结一下模板吧 这题还是没意思的,直接暴力搜,不过我写的很烂,可能就是这个原因吧,看了别人的模板,觉得不错. 学了个单词”lexicography“ 字典序,又吃了没文化的亏,wa一次 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath>

hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) &amp;&amp; hdu-1015 Safecracker(简单搜索)

http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心外,还需要强力的剪枝. 奇偶性剪枝:参考 http://www.cppblog.com/Geek/archive/2010/04/26/113615.html 1 #include <iostream> 2 #include <cstring> 3 #include <cstdi

hdu1015 dfs暴力搜

很水的题吧,不过以后注意环这种要考虑头尾情况 为了省力素数表范围打错了,太坑了 #include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <string> #include <queue> #include <stack> #include <algorithm

Hdu1015&amp;&amp;寒假作业第二组I题

题意是A-Z对应1-26,然后给个目标数字和字符串,看看字符串里的某5个字符的组合能不能使v - w^2 + x^3 - y^4 + z^5 = target等式成立,其实多写几个循环也可以达到目的,不过应该会超时,所以还是dfs. result数组保存最后5个数字,注意要用sort先降序排序,sort默认升序,得加个compare函数,因为本题可能有多解,人家要字典序最大的.num1数组是用来标记该数字被用过没有,注意要memset一下(忘了memset于是每次只能对一组数据也是醉了). #i

HDU-1015(暴力)

Safecracker 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 des

hdu1016 Prime Ring Problem dfs 素数打表

意思是给你一个数n,要构成一个素数环,这个素数由1-n组成,它的特征是选中环上的任意一个数字i,i与它相连的两个数加起来都分别为素数,满足就输出. 这个题的做法和hdu1015做法差不多都是使用dfs 回溯.不同之处在于这个要全部搜索,而hdu1015只需要搜索第一组就可以. 其次在这个题目中使用素数打表的方式简化素数判定,在一定情况下也是对效率有所提高的. Prime Ring Problem Time Limit: 4000/2000 MS (Java/Others) Memory Limi