算法竞赛入门经典第五章例题5-9 Database UVA - 1592

https://vjudge.net/problem/UVA-1592

#include<iostream>
#include<vector>
#include<string>
#include<map>
using namespace std;
#pragma warning(disable:4996)
int vis[10005][11];
int dat[10005][11];
map<string, int> IDCache;
vector<string> StrCache;
int ID(string s) { 
    if (IDCache.count(s)) return IDCache[s];
    StrCache.push_back(s);
    return IDCache[s] = StrCache.size()-1;
}
int r, c,pos,be,ans_c1,ans_c2,ans_r1,ans_r2;
int main(){
#ifdef _DEBUG
    freopen("in", "rb", stdin);
    freopen("out", "wb", stdout);
#endif // _DEBUG
    string st;
    while (cin >> r >> c) {
        getline(cin, st);
        for (int i = 1; i <= r; ++i) {
            getline(cin, st), be = 0;
            for (int j = 1; j <= c; ++j) {
                pos = st.find_first_of(",\r",be);
                if (pos == string::npos) pos = st.length();
                dat[i][j] = ID(st.substr(be, pos - be));
                be = pos + 1;
            }
        }
        bool _ok = false;
        for (int c1 = 1; c1 <= c; ++c1) {
            for (int c2 = c1+1; c2 <= c; ++c2) {
                map<pair<int,int>, int> vis;
                for (int k = 1; k <= r; ++k) {
                    pair<int,int> nn(dat[k][c1], dat[k][c2]); 
                    if (vis.count(nn)) {
                        ans_c1 = c1, ans_c2 = c2, ans_r1 = vis[nn], ans_r2 = k; _ok = true; break;
                    }
                    else vis[nn] = k;
                }
                if (_ok) break;
            }
            if (_ok) break;
        }
        if (_ok) printf("NO\n%d %d\n%d %d\n", ans_r1, ans_r2, ans_c1, ans_c2);
        else printf("YES\n");
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值