1068

作者: 峡迩 | 来源:发表于2017-09-05 16:06 被阅读0次
    // PATn.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include<iostream>
    #include<string>
    #include<vector>
    #include<tuple>
    
    using namespace std;
    
    vector<tuple<unsigned, unsigned>> get_aboard(unsigned m,unsigned n)
    {
    
        vector<tuple<unsigned, unsigned>> ret;
        
        ret.push_back(make_tuple(m - 1, n - 1));
        ret.push_back(make_tuple(m - 1, n));
        ret.push_back(make_tuple(m - 1, n + 1));
        ret.push_back(make_tuple(m, n - 1));
        ret.push_back(make_tuple(m, n + 1));
        ret.push_back(make_tuple(m + 1, n - 1));
        ret.push_back(make_tuple(m + 1, n));
        ret.push_back(make_tuple(m + 1, n + 1));
    
        return ret;
    }
    
    int main()
    {
        unsigned m, n;
        long long tol;
        cin >> m >> n >> tol;
    
        vector<vector<long long>> data;
        for (unsigned i = 0; i < n; ++i)
        {
            vector<long long> tmp_row;
            for(unsigned j = 0; j < m; ++j)
            {
                long long tmp;
                cin >> tmp;
                tmp_row.push_back(tmp);
            }
            data.push_back(tmp_row);
        }
    
        vector<tuple<unsigned, unsigned>> green;
        for (unsigned i = 1; i < (n-1); ++i)
        {
            for (unsigned j = 1; j < (m-1); ++j)    //必须有8个相邻数值!
            {
                bool is_green = true;
                auto tmp = get_aboard(j, i);
                for (auto &r : tmp)
                {
                    auto chazhi = abs(data[i][j] - data[get<1>(r)][get<0>(r)]);
                    if (chazhi <= tol)//超过的反义词,小于等于!
                    {
                        is_green = false;
                        break;
                    }   
                }
    
                if (is_green)
                    green.push_back(make_tuple(j, i));      //绿色的坐标值,转换为输出需要加1!
            }
        }
    
        if (green.size() == 0)
            cout << "Not Exist";
        if (green.size() > 1)
            cout << "Not Unique";
        if (green.size() == 1)
        {
            unsigned i = get<1>(green[0]);
            unsigned j = get<0>(green[0]);
            cout << "("<<(j+1)<<", "<<(i+1)<<"): "<<data[i][j];
        }
    
        system("pause");
        return 0;
    }
    
    

    相关文章

      网友评论

          本文标题:1068

          本文链接:https://www.haomeiwen.com/subject/dyaujxtx.html