Test Instructions:
Give the N row m column A total of n*m strings, and ask if there are different rows r1,r2, with the same C1,C2 columns. i.e. (R1,C1) = (R2,C1); (r1,c2) = (R2,C2);
Such as
2 3
123,456,789
123,654,789
(1,3) on correspondence (3,3)
If this corresponds, output no, then output two line number, two column number. Otherwise, the output is yes.
Analysis:
Map each string to a value.
Enumerates any two columns, forming a pair of pairs, enumerating any two rows for equality, and any two-column combination C (10,2) = 45 rows with a maximum of 10000 rows.
In fact, this method is very slow, just to practice STL, normal practice will use a char array and hash
1#include <bits/stdc++.h>2 Const intMAXR =10000+5;3 Const intMAXC =Ten+5;4 using namespacestd;5typedef pair<int,int>PII;6 intN, M, CNT;7 intDB[MAXR][MAXC];8map<string,int>ID;9 Ten voidDebug ()//observe the values of the DP array mappings One { A for(inti =0; I < n; i++) - { - for(intj =0; J < M; J + +) the { -cout << Db[i][j] <<" "; - } -cout<<"\ n"; + } - + } A intID (Const string&s) at { - if(Id.count (s)) - returnId[s]; - Else returnId[s] = + +CNT; - } - voidSolve () in { - //look for any two columns and see if any two rows are equal any two columns combined 45 rows total 10000 loops 45W times to for(intC1 =0; C1 < m; c1++) + { - for(intC2 = C1 +1; C2 < m; c2++) the { *MAP<PII,int> D;//note the survival cycle, which only exists in any two-column loop $ for(inti =0; I < n; i++)Panax Notoginseng { -PII p =Make_pair (DB[I][C1], db[i][c2]); the if(D.count (p)) + { Aprintf"no\n"); theprintf"%d%d\n", d[p]+1, i+1); +printf"%d%d\n", c1+1, c2+1); - return; $ } $D[P] =i; - } - } the } -printf"yes\n");Wuyi } the intMain () - { Wu //freopen ("1.txt", "R", stdin); - strings; About while(Getline (cin,s)) $ { - StringStream SS (s); - if(! (SS >> n >> m)) Break; - for(inti =0; I < n; i++) A { + stringT; the getline (cin,t); - for(intj =0; J < T.length (); J + +) $ { the if(T[j] = =',') T[j] =' '; the Else if(T[j] = =' ') T[j] ='$'; the } the StringStream St (t); - for(intj =0; J < M; J + +) in { the stringT1; theSt >>T1; About //cout<<t1<< "\ n"; theDB[I][J] =ID (t1); the } the } + //debug (); - solve (); the }Bayi return 0; the}
UVA 1592 Database (STL)