算法竞赛入门经典第五章例题5-9 Database UVA - 1592
2018-01-08 12:10
826 查看
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"); } }
相关文章推荐
- 【例题5-9 UVA - 1592】Database
- 《算法竞赛入门经典2ndEdition 》例题5-9 数据库(Database, Uva1592)
- 算法竞赛入门经典第五章例题5-8 Unix ls UVA - 400
- UVa #1592 Database (例题5-9)
- 算法竞赛入门经典第五章例题5-2 The Blocks Problem UVA - 101
- 算法竞赛入门经典第五章例题5-3 Andy's First Dictionary UVA - 10815
- 例题5-9 UVA 1592 Database数据库
- 算法竞赛入门经典第五章例题5-4 Ananagrams UVA - 156
- Uva1592 Database 【map应用】【例题5-9】
- 算法竞赛入门经典第五章例题5-6 Team Queue UVA - 540
- 算法竞赛入门经典第五章例题5-1 Where is the Marble? UVA - 10474
- UVa 1592 Database
- 紫书章五例题9 数据库 UVA 1592 (map+vector)
- 算法竞赛入门经典第四章例题4-6 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang) UVA - 12412
- 算法竞赛入门经典第五章例题5-7 Ugly Numbers UVA - 136
- UVa 1592 - Database
- UVA 1592 Database
- 【UVa 1592】Database
- 紫书章五例题9 数据库 UVA 1592 (map+vector)
- Database, UVa 1592