HDU 1716(排列2)解题纠错
2011-04-03 08:31
441 查看
以下来自http://zhidao.baidu.com/question/246928784.html
(1)最后一组数据后面没有空行;
(2)千位数字相同的在同一行,即如果第1位不同,则应换行,而且行尾不能有空格;
(3)输出4位数,即第1位是0不要输出;
(4)没有实现"如果四张卡片都是0,则输入结束"的要求.
以下修改AC:
#include <stdio.h> #include <string.h> int main() { int a[4]; int che_c[24][4]; bool change=false; while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])!=EOF) { int x,y,z,m; int hang=0; for(x=0;x<4;x++) { //printf("%d",a[x]); for(y=0;y<4;y++) { if(y!=x) for(z=0;z<4;z++) { if(z!=x&&z!=y) for(m=0;m<4;m++) { if(m!=x&&m!=y&&m!=z) {//printf("%c%c%c%c",a[x],a[y],a[z],a[m]); che_c[hang][0]=a[x]; che_c[hang][1]=a[y]; che_c[hang][2]=a[z]; che_c[hang][3]=a[m]; hang++; } } } } } int check=0; int move=0; int repeat=0; while(check<24) { while(move<24&&che_c[check][3]!=-25670) { if(che_c[move][0]==che_c[check][0]&&che_c[move][1]==che_c[check][1]&&che_c[move][2]==che_c[check][2]&&che_c[move][3]==che_c[check][3]) { repeat++; if(repeat>=2) che_c[move][3]=-25670; //break; } move++; } check++; move=check; //move=0; repeat=0; } int output=0; int hang_t=0; while(output<24) { if(che_c[output][3]!=-25670) {//if(che_c[output][0]!=che_c[output-1][0]&&output>0) //printf("/n"); printf("%d%d%d%d",che_c[output][0],che_c[output][1],che_c[output][2],che_c[output][3]); printf(" "); } output++; } printf("/n"); } }
(1)最后一组数据后面没有空行;
(2)千位数字相同的在同一行,即如果第1位不同,则应换行,而且行尾不能有空格;
(3)输出4位数,即第1位是0不要输出;
(4)没有实现"如果四张卡片都是0,则输入结束"的要求.
以下修改AC:
#include <stdio.h> #include <string.h> int main() { int a[4]; int che_c[24][4]; int case_number = 0; //added //bool change=false; //while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])!=EOF) while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])!=EOF && (a[0]||a[1]||a[2]||a[3])) { if (case_number > 0) printf("/n"); //added case_number++; //added int x,y,z,m; int hang=0; for(x=0;x<4;x++) { //printf("%d",a[x]); for(y=0;y<4;y++) { if(y!=x) for(z=0;z<4;z++) { if(z!=x&&z!=y) for(m=0;m<4;m++) { if(m!=x&&m!=y&&m!=z) {//printf("%c%c%c%c",a[x],a[y],a[z],a[m]); che_c[hang][0]=a[x]; che_c[hang][1]=a[y]; che_c[hang][2]=a[z]; che_c[hang][3]=a[m]; hang++; } } } } } int check=0; int move=0; int repeat=0; while(check<24) { while(move<24&&che_c[check][3]!=-25670) { if(che_c[move][0]==che_c[check][0]&&che_c[move][1]==che_c[check][1]&&che_c[move][2]==che_c[check][2]&&che_c[move][3]==che_c[check][3]) { repeat++; if(repeat>=2) che_c[move][3]=-25670; //break; } move++; } check++; move=check; //move=0; repeat=0; } int output=0; //int hang_t=0; int out_count = 0; //added int last_number; //added while(output<24) { if(che_c[output][3]!=-25670 && che_c[output][0])//if(che_c[output][3]!=-25670) {//if(che_c[output][0]!=che_c[output-1][0]&&output>0) //printf("/n"); if (out_count > 0) //added { printf("%c", last_number == che_c[output][0] ? ' ' : '/n');//printf(" "); } last_number = che_c[output][0]; //added out_count++; //added printf("%d%d%d%d",che_c[output][0],che_c[output][1],che_c[output][2],che_c[output][3]); } output++; } printf("/n"); } return 0; }
相关文章推荐
- 2018.1.22【HDU - 1716】解题报告(排列STL)
- hdu 1716 排列2(stl next_permutation)
- HDU 1716 - 排列2
- HDU 1716 排列2 + poj 1833
- hdu 1716排列2
- HDU 1716 排列2 字典序
- HDU 1716 排列2(排列生成,,next_permutation())
- HDU 1716 排列2
- HDU--杭电--1716--排列2--深度优先搜索
- HDU 1716 排列2
- hdu 1716 排列2 (dfs)
- hdu 1716 排列2
- HDU-#1716 排列2(不重复排列+字典序)
- HDU-1716 排列2 (DFS)
- HDU 1716 排列 简单的DFS
- HDU--杭电--1716--排列2--深度优先搜索--此类中的基础题,也是水题
- 又是全排列问题(hdu 1716)
- HDU 1716 排列2
- hdu 1716 排列2(水题)
- HDU-1716 排列2 (DFS)