hdu 1015 (DFS,暴力)
2013-05-02 09:34
309 查看
点击打开链接
分析:
可以用DFS,也可以暴力5循环。。。。
分析:
可以用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; }
相关文章推荐
- hdu 1015 Safecracker 暴力dfs
- HDU-1015 Safecracker(DFS+暴力回溯 / 五重循环)
- HDU 1015Safecracker(算是很简单的dfs了,却debug了很久很久)
- hdu 1010 Tempter of the Bone(dfs暴力)
- POJ 1248 && HDU 1015 Safecracker(dfs)
- hdu - beautiful number-5179 - 暴力打表&DFS&数位DP
- 暴力枚举,dfs(连连看,HDU 4272)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- hdu 5547 Sudoku dfs 暴力回溯 解题报告
- HDU 1426 Sudoku Killer ( 暴力dfs 输入输出格式坑)
- hdu 4462 Scaring the Birds【Dfs+暴力判断】
- HDU 5706 GirlCat (DFS,暴力)
- HDU 5113 Black And White(暴力dfs+减枝)
- HDU 1015 Safecracker (暴力枚举)
- HDU 1015 Safecracker(DFS)
- hdu 4770 Lights Against Dudely(暴力枚举dfs)
- HDU 4431 Mahjong (DFS,暴力枚举,剪枝)
- HDU 1010 Tempter of the Bone(DFS+暴力+标记)
- HDU1045 Fire Net 暴力搜索DFS
- HDU 1015 Safecracker(DFS)