(赛后补题)B - Latin Squares Gym - 101652O

我真的服了,明明要多组输入,为什么不说!为什么不说!为什么不说!啊啊啊啊啊!我做了两个小时啊,我真服了这煞笔题,带着怨恨往下写,气死我了气死我了

题意:多组输入(虽然题目里面丝毫没提起,怎么,真是做阅读理解呢?此处省略一万个消音词)

给你一个n*n的数组,询问这个数组如果满足:

1.每个数,在每一行,每一列,都只出现一次,说白了,这个数所在的这一行和列都不能有和他重复的,那就输出Not Reduced;

2.在条件1的基础上,如果这个数组的第一行和第一列,都是由小到大排列的,那就输出Reduced;

3.如果都不满足,输出No

注意,输入的形式必须是字符形式,因为会输入大写字母和数字。

因为这个题给的n很小,只有36,所以我们可以直接暴力,三层循环也不会超时,放心做。

原题:Problem O — limit 1 second Latin Squares A Latin Square is an n-by-n array filled with n different digits, each digit occurring exactly once in each row and once in each column. (The name “Latin Square” was inspired by the work of Leonhard Euler, who used Latin characters in his papers on the topic.) A Latin Square is said to be in reduced form if both its top row and leftmost column are in their natural order. The natural order of a set of digits is by increasing value. Your team is to write a program that will read an n-by-n array, and determine whether it is a Latin Square, and if so, whether it is in reduced form. Input The first line of input contains a single integer n (2 ≤ n ≤ 36). Each of the next n lines contains n digits in base n, with the normal digits ‘0’ through ‘9’ for digit values below 10 and uppercase letters ‘A’ through ‘Z’ representing digit values 10 through 35. All digits will be legal for base n; for instance, if n is 3, the only legal characters in the n input lines describing the square will be ‘0’, ‘1’, and ‘2’. Output If the given array is not a Latin Square, print “No” on a single line (without quotation marks). If it is a Latin Square, but not in reduced form, print “Not Reduced” on a single line (without quotation marks). If it is a Latin Square in reduced form, print “Reduced” on a single line (without quotation marks)

3 012 120 201 Reduced 4 3210 0123 2301 1032 Not Reduced 11 0123458372A A9287346283 0285475A834 84738299A02 1947584037A 65848430002 038955873A8 947530200A8 93484721084 95539A92828 04553883568 No

#include <bits/stdc++.h>

using namespace std;
int main()
{
    char c[40][40];
    int i,j,n,k;
    int f;
    while(scanf("%d",&n)!=EOF)//多组输入奥!!!!!
{   f=0;
    for(i=1;i<=n;i++)
    {getchar();//因为前面输入n的时候带着回车,所以这里需要一个getchar缓冲一下
        for(j=1;j<=n;j++)
        {
            scanf("%c",&c[i][j]);
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                if(k!=j)//看看这一行里面有没有和它相等的
                {
                    if(c[i][j]==c[i][k]&&f==0)
                    {
                        f=2;

                    }
                }
            }
            for(k=1;k<=n;k++)//同样,看这一列里面有没有和他相等的
            {
                if(k!=i)
                {
                    if(c[i][j]==c[k][j]&&f==0)
                    {
                        f=2;
                    }
                }
            }
        }
    }
    for(i=2;i<=n;i++)
    {
        if(c[1][i-1]>=c[1][i]&&f==0)
        {
            f=1;
        }
    }
    for(i=2;i<=n;i++)
    {
        if(c[i-1][1]>=c[i][1]&&f==0)
        {
            f=1;
        }
    }
    if(f==1)
        printf("Not Reduced\n");
    else if(f==2)
        printf("No\n");
    else
    printf("Reduced\n");
}

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值