PAT1068 万绿丛中一点红 (20 分)

14 篇文章 0 订阅

题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805265579229184

坑点:

  • 题目中的行列和我们输入的行列是相反的,输出也要反着输。
  • 条件除了与周围不同以外还有独一无二。

#include <iostream>
#include <map>

using namespace std;

const unsigned maxn = 1005;

int x[maxn][maxn];

map <int, int>pp;

void solve()
{
    int m, n, k;
    cin>>n>>m>>k;
    for(int i = 0; i < m; i++)
        for(int j = 0; j < n; j++)
        {
            cin>>x[i][j];
            pp[x[i][j]]++;
        }
    int r[8][2] = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 1},{1, -1}, {1, 0}, {1, 1}};
    int re[2];
    int co = 0;
    for(int i = 0; i < m; i++)
    {
        for(int j = 0; j < n; j++)
        {
            bool fa =  true;
            if(pp[x[i][j]] > 1)
                continue;
            for(int h = 0; h < 8; h++)
            {
                int a = -1, b = -1;
                if(r[h][0] + i >= 0 && r[h][0] + i < m)
                    a = r[h][0] + i;
                if(r[h][1] + j >= 0 && r[h][1] + j < n)
                    b = r[h][1] + j;
                if(a != -1 && b != -1)
                {
                    int mm = x[a][b] - x[i][j];
                    if(mm < 0)
                        mm *= -1;
                    if(mm <= k)
                    {
                        fa = false;
                        break;
                    }
                }
            }
            if(fa)
            {
                co++;
                re[0] = i;
                re[1] = j;
            }
            if(co > 1)
                break;
        }
        if(co > 1)
            break;
    }
    if(co == 1)
        cout<<"("<<re[1] + 1<<", "<<re[0] + 1<<"): "<<x[re[0]][re[1]]<<endl;
    else if(co == 0)
        cout<<"Not Exist"<<endl;
    else
        cout<<"Not Unique"<<endl;
    return;
}

int main()
{
    solve();
    return 0;
}

                                                                                                                                                               20分一般类,注意细节       

                                                                                                                                                            2018年9月17日 15:58:07   

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值