【HDOJ】1015 Safecracker

【题目】http://acm.hdu.edu.cn/showproblem.php?pid=1015

【报告】

    题目写的很长,忽略一系列废话,题意就是求一个方程v - w^2 + x^3 - y^4 + z^5 = target 的解,其中v,w,x,y,z是大写字母,其值相当于大写字母的顺序(比如'A'是1,'Z'是26),并且是由输入给定的字母范围,不能重复。

    水题,可以用递归做,也可以用回溯,当然更可以直接5个for爆一下。

    只要注意一下,输出要字典序最大的(很搞有木有),这个只需要开始排序一下,从大到小再爆就可以了。

【程序】

// Task: 1015 Safecracker
// Designer: Rsky 2013/08/12
#include
#include
#include
#include
#include
using namespace std;
string st;
int t;
inline bool calc(int v,int w,int x,int y,int z)
{
    return (v-w*w+x*x*x-y*y*y*y+z*z*z*z*z)==t;
}
inline bool solve()
{
    for (int v=0;v
        for (int w=0;w
            if (v!=w)
            for (int x=0;x
                if (v!=x&&w!=x)
                for (int y=0;y
                    if (v!=y&&w!=y&&x!=y)
                    for (int z=0;z
                        if (v!=z&&w!=z&&x!=z&&y!=z)
                        if (calc(st[v]-'A'+1,st[w]-'A'+1,st[x]-'A'+1,st[y]-'A'+1,st[z]-'A'+1))
                        {
                            cout << st[v] << st[w] << st[x] << st[y] << st[z] << endl;
                            return true;
                     

posted @ 2013-08-12 19:20  为美好世界献上珂学  阅读(93)  评论(0)    收藏  举报