社区讨论

改了还是60…dalao求解答

P1618三连击(升级版)参与者 5已保存回复 10

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
10 条
当前快照
1 份
快照标识符
@mi6lhikr
此快照首次捕获于
2025/11/20 06:49
4 个月前
此快照最后确认于
2025/11/20 06:49
4 个月前
查看原帖
第一次60,下载大概是第二个数据感觉是单复数的问题。然后加上判断第二个三位数的个位数只要是2的倍数就不算。然后还是60…只是错的测试点变了。很懵。第二个三位数可能不是2的倍数吗…为什么错了上次没错的测试点。分别是两次的代码:
第一次:
CPP
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
int a,b,c,book[10],yi,er,san,la,lb,lc,mark[10],flag;
void babc()
{
    yi=book[1]*100 + book[2]*10 + book[3];
    er=book[4]*100 + book[5]*10 + book[6];
    san=book[7]*100 + book[8]*10 + book[9];
    la=yi/a;    lb=er/b;    lc=san/c;
    if ( la==lb && lb==lc )
    {
        flag=1;
         for (int j=1;j<=9;j++)
         {
             printf("%d",book[j]);
             flag++;
             if (flag==4 || flag==7)
             {
                printf(" ");
             }
         }
         printf("\n");
         return;
    }
    else
        return;
}
void dfs(int depth)
{
     if (depth > 9)
     {
        babc();
        return;
     }
     for (int i=1;i<=9;i++)
     {
         if (mark[i]==0)
         {
             book[depth]=i;
             mark[i]=1;
             dfs(depth+1);
             mark[i]=0;
         }
       }
    return;
}
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    dfs(1);
    if (!flag) printf("No!!!");
    return 0;
}

回复

10 条回复,欢迎继续交流。

正在加载回复...