HDU3344(小广搜+小暴力

本文介绍了一种解决Kakuro数字谜题的方法,并提供了一个具体的实现案例。该程序能够根据给定的输出文件反向生成输入文件内容,通过解析数字布局来形成特定的输出格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Kakuro Extension Extension

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 507    Accepted Submission(s): 248


Problem Description
You know ,I'm a lazy guy and write problem description is a very very boring thing.So , I would not repeat the rule of Kakuro again , Please look at this.But things are different again,contray to the problem above,this time you should work out the input file according to the output file.
 

 

Input
The first line of the inputs is T, which stands for the number of test cases you need to solve.
Then T case follow:
Each test case starts with a line contains two numbers N,M (2<=N,M<=100)and then N lines follow, each line contains M columns, either ‘_’ or 1~9. You can assume that the first column of the first line is ’_’.
 

 

Output
Output N lines, each line contains M parts, each part contains 7 letters. The m parts are seperated by spaces.Output a blank line after each case.
 

 

Sample Input
2 6 6 _ _ _ _ _ _ _ _ 5 8 9 _ _ 7 6 9 8 4 _ 6 8 _ 7 6 _ 9 2 7 4 _ _ _ 7 9 _ _ 5 8 _ _ _ _ _ _ _ _ _ 1 9 9 1 1 8 6 _ _ 1 7 7 9 1 9 _ 1 3 9 9 9 3 9 _ 6 7 2 4 9 2 _
 

 

Sample Output
XXXXXXX XXXXXXX 028\XXX 017\XXX 028\XXX XXXXXXX XXXXXXX 022\022 ....... ....... ....... 010\XXX XXX\034 ....... ....... ....... ....... ....... XXX\014 ....... ....... 016\013 ....... ....... XXX\022 ....... ....... ....... ....... XXXXXXX XXXXXXX XXX\016 ....... ....... XXXXXXX XXXXXXX XXXXXXX 001\XXX 020\XXX 027\XXX 021\XXX 028\XXX 014\XXX 024\XXX XXX\035 ....... ....... ....... ....... ....... ....... ....... XXXXXXX 007\034 ....... ....... ....... ....... ....... ....... XXX\043 ....... ....... ....... ....... ....... ....... ....... XXX\030 ....... ....... ....... ....... ....... ....... XXXXXXX
 

 

Author
shǎ崽
 

 

Source
 

 

Recommend
 
 
 
 
 

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char a[105][105];

void pd(int x,int y,int m,int n)
{
    if(a[x][y]>='1'&&a[x][y]<='9')
    {
        printf(".......");
        return ;
    }
    int sum1=0,sum2=0;
    int flag1=0;
    int flag2=0;
    if(x==m)
        flag1=1;
    if(y==n)
        flag2=1;
    for(int i=x+1; i<=m; i++)
    {
        if(a[x+1][y]=='_')
            flag1=1;
        if(a[i][y]=='_')
            break;
        sum1=sum1+(a[i][y]-'0');
    }
    for(int j=y+1; j<=n; j++)
    {
        if(a[x][y+1]=='_')
            flag2=1;
        if(a[x][j]=='_')
            break;
        sum2=sum2+(a[x][j]-'0');
    }
    if(flag1==1&&flag2==1)
    {
        printf("XXXXXXX");

    }
    else if(flag1==1&&flag2==0)
    {
            printf("XXX");
            printf("\\");
            printf("%03d",sum2);


    }
    else if(flag1==0&&flag2==1)
    {
            printf("%03d",sum1);
            printf("\\");
            printf("XXX");
    }
    else if(flag1==0&&flag2==0)
    {
            printf("%03d\\%03d",sum1,sum2);
    }

}
int main()
{
    int m,n;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(a,0,sizeof(a));
        scanf("%d%d",&m,&n);
        getchar();
        for(int i=1; i<=m; i++)
        {
            for(int j=1; j<=n; j++)
            {
                //scanf("%c",&a[i][j]);
                cin >> a[i][j];
            }

        }
        char ch=' ';
        for(int i=1; i<=m; i++)
        {
            for(int j=1; j<=n; j++)
            {
                /*if(a[1][1]!='_')
                    a[1][1]='_';*/
                pd(i,j,m,n);
                if(j!=n)
                    printf("%c",ch);
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

转载于:https://www.cnblogs.com/13224ACMer/p/4445093.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值