hdu_1015_Safecracker(模拟)

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

够暴力吧!

先排序,然后循环找。。。

#include <iostream>
#include <cstring>
using namespace std;

int cmp( const void *a , const void *b )
{
    return *(char *)a - *(char *)b;
}
int main(int argc, char *argv[])
{
    while(1)
    {
        int target;
        char a[30] = " ";
        cin >> target >> a;
        if(target == 0 && strcmp(a,"END") == 0)
            return 0;
        qsort(a,strlen(a),sizeof(a[0]),cmp);
        int len = strlen(a);
        int x1,x2,x3,x4,x5;
        int y1,y2,y3,y4,y5;
        int max = 0;
        for(int i = 0;i < len;i++)
        {
            for(int j = 0;j < len;j++)
            {
                for(int k = 0;k < len;k++)
                {
                    for(int m = 0;m < len;m++)
                    {
                        for(int n = 0;n < len;n++)
                        {
                            if(a[i] != a[j] && a[i] != a[k] && a[i] != a[m] && a[i] != a[n] && a[k] != a[m] && a[k] != a[n] && a[m] != a[n])
                            {
                                x1 = a[i] - 64,x2 = a[j] - 64,x3 = a[k] - 64,x4 = a[m] - 64,x5 = a[n] - 64;
                                if(x1 - x2*x2 + x3*x3*x3 - x4*x4*x4*x4 + x5*x5*x5*x5*x5 == target)
                                {
                                         y1 = i,y2 = j, y3 = k,y4 = m,y5 = n;
                                         max = 1;
                                }
                            }
                        }
                    }
                }
            }
        }
        if(max == 0)
            cout << "no solution" << endl;
        else
            cout << a[y1] << a[y2] << a[y3] << a[y4] << a[y5] << endl;
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值