Http://livearchive.onlinejudge.org/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 3736
Problem solving: It is critical to understand the question ..
Because there are only two colors .. So binary enumeration... If a set has only one color (all is 0, or all is 1), false is returned. Otherwise, true is returned ..
Reading is painful .. The eggs are broken ..
Use stringstream.
Http://www.cppblog.com/Sandywin/archive/2007/07/13/27984.html
View code
# Include <iostream> # Include < String . H> # Include <Algorithm> # Include <Vector> # Include <Stdio. h># Include <Sstream> Using Namespace STD; Int N, m; String STR, ans; Const Int Maxn = 10000 ; Vector < Int > Node [maxn]; Int Check (Int ID ){ Int Num = 0 ; For ( Int I = 1 ; I <= m; I ++ ) {Num = 0 ; For ( Int J = 0 ; J <node [I]. Size (); j ++) If (ID &( 1 < Node [I] [J]) num ++ ; If (Num = 0 | Num = node [I]. Size ()) Return 0 ;} Return 1 ;} Int Main (){ Int Test; scanf ( " % D " ,& Test ); While (Test -- ) {Scanf ( " % D " , & N ,& M); Getline (CIN, STR ); For ( Int I = 1 ; I <= m; I ++ ) Node [I]. Clear (); For ( Int I = 1 ; I <= m; I ++ ) {Getline (CIN, STR); stringstream sin; sin < STR; Int A; While (SIN> A) node [I]. push_back ( - 1 ); // Cout <A <Endl; // Cout <Endl; } Int Mm = 1 < N; Int Flage = 0 ; For ( Int I = 1 ; I <mm; I ++ ) If (Check (I) {flage = 1 ; Break ;} If (Flage) ans + = ' Y ' ; Else Ans + = ' N ' ; // Getline (CIN, STR ); } Cout < Ans; Return 0 ;}