您的位置:首页 > 其它

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

2018-01-08 12:10 786 查看
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");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: