您的位置:首页 > 其它

hdu 1015 (DFS,暴力)

2013-05-02 09:34 309 查看
点击打开链接

分析:

可以用DFS,也可以暴力5循环。。。。

#include"stdio.h"
#include"string.h"
#include"algorithm"
using namespace std;
int fun(int a,int b,int c,int d,int e)
{
if(a==b||a==c||a==d||a==e)return 0;
if(b==c||b==d||b==e)return 0;
if(c==d||c==e)return 0;
if(d==e)return 0;
return 1;
}
int cmp(char a,char b)
{
return a>b;
}
int main()
{
int n,t,len;
char str[15];
int v,w,x,y,z,f;
int vv,ww,xx,yy,zz;
while(scanf("%d %s",&n,str)!=-1)
{
if(n==0&&strcmp(str,"END")==0)break;
t=0;
f=0;
len=strlen(str);
sort(str,str+len,cmp);
for(v=0;str[v];v++)
{
for(w=0;str[w];w++)
{
for(x=0;str[x];x++)
{
for(y=0;str[y];y++)
{
for(z=0;str[z];z++)
{
if(fun(v,w,x,y,z))
{
vv=str[v]-'A'+1;
ww=str[w]-'A'+1;
xx=str[x]-'A'+1;
yy=str[y]-'A'+1;
zz=str[z]-'A'+1;
if(vv-ww*ww+xx*xx*xx
-yy*yy*yy*yy+zz*zz*zz*zz*zz==n)
{
f=1;
printf("%c%c%c%c%c\n",str[v],str[w],str[x],str[y],str[z]);
break;
}
}
}if(f)break;
}if(f)break;
}if(f)break;
}if(f)break;
}
if(!f)printf("no solution\n");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: