SRM 208 DIV 1 Level One

Source: Internet
Author: User

Question: http://www.topcoder.com/stat? C = problem_statement & pm = 2923 & rd = 5854

 

# Include <iostream> <br/> # include <vector> <br/> # include <ctime> <br/> # include <sstream> <br/> using namespace STD; <br/> const int max_num = 50; <br/> int height [max_num] [max_num] = {0 }; <br/> class tallpeople <br/> {<br/> Public: <br/> vector <int> getpeople (vector <string> people); <br/> }; <br/> vector <int> tallpeople: getpeople (vector <string> People) <br/>{< br/> int rows = people. size (); <br/> int Cols = 0; <br/> int h = 0; <br/> stringstream SS; <br/> SS <people [0]; <br/> while (SS> H) Cols ++; <br/> // find Max and Min <br/> int max_row =-1, min_col =-1; <br/> // build height matrix <br/> for (INT I = 0; I <rows; I ++) <br/>{< br/> int min_cur_row =-1; <br/> SS. clear (); <br/> SS <people [I]; <br/> for (Int J = 0; j <Cols; j ++) <br/> {<br/> SS> H; <br/> height [I] [J] = H; <br/> If (min_cur_row =-1) <br/> min_cur_row = Height [I] [J]; <br/> else <br/> min_cur_row = min_cur_row> height [I] [J]? Height [I] [J]: min_cur_row; <br/>}< br/> If (max_row =-1) <br/> max_row = min_cur_row; <br/> else <br/> max_row = max_row> min_cur_row? Max_row: min_cur_row; <br/>}</P> <p> for (INT I = 0; I <Cols; I ++) <br/>{< br/> int max_cur_col =-1; <br/> for (Int J = 0; j <rows; j ++) <br/>{< br/> If (max_cur_col =-1) <br/>{< br/> max_cur_col = height [J] [I]; <br/>}< br/> else <br/> max_cur_col = max_cur_col> height [J] [I]? Max_cur_col: height [J] [I]; <br/>}< br/> If (min_col =-1) <br/> min_col = max_cur_col; <br/> else <br/> min_col = min_col> max_cur_col? Max_cur_col: min_col; <br/>}< br/> // return result <br/> vector <int> result; <br/> result. push_back (max_row); <br/> result. push_back (min_col); <br/> return result; <br/>}< br/> bool kawigiedit_runtest (INT testnum, vector <string> P0, bool hasanswer, vector <int> P1); <br/> int main () {<br/> bool all_right; <br/> all_right = true; <br/> vector <string> P0; <br/> vector <int> P1; <br/> {<br/> // ----- Test 0 ----- <br/> string t0 [] = {"9 2 3",/<br/> "4 8 7" }; <br/> paiassign (T0, t0 + sizeof (t0)/sizeof (T0 [0]); <br/> int T1 [] = {4, 7}; <br/> p1.assign (T1, t1 + sizeof (T1)/sizeof (T1 [0]); <br/> all_right = kawigiedit_runtest (0, P0, true, P1) & all_right; <br/> // ---------------- <br/>}< br/> return 0; <br/>}< br/> bool kawigiedit_runtest (INT testnum, vector <string> P0, bool hasanswer, vector <int> P1) {<Br/> cout <"test" <testnum <": [" <"{"; <br/> for (INT I = 0; INT (distinct size ()> I; ++ I) {<br/> if (I> 0) {<br/> cout <","; <br/>}< br/> cout <"/" "<P0 [I] <"/""; <br/>}< br/> cout <"}"; <br/> cout <"]" <Endl; <br/> tallpeople * OBJ; <br/> vector <int> answer; <br/> OBJ = new tallpeople (); <br/> clock_t starttime = clock (); <br/> answer = obj-> getpeople (P0); <br/> clock_t endtime = Cl Ock (); <br/> Delete OBJ; <br/> bool res; <br/> res = true; <br/> cout <"Time: "<double (endtime-starttime)/clocks_per_sec <" seconds "<Endl; <br/> If (hasanswer) {<br/> cout <" desired answer: "<Endl; <br/> cout <"/t "<" {"; <br/> for (INT I = 0; int (p1.size ()> i; ++ I) {<br/> if (I> 0) {<br/> cout <","; <br/>}< br/> cout <P1 [I]; <br/>}< br/> cout <"}" <Endl; <br/>}< br/> cout <"Your answer:" <Endl; <br/> cout <"/t" <"{"; <br/> for (INT I = 0; INT (answer. size ()> I; ++ I) {<br/> if (I> 0) {<br/> cout <","; <br/>}< br/> cout <answer [I]; <br/>}< br/> cout <"}" <Endl; <br/> If (hasanswer) {<br/> If (answer. size ()! = P1.size () {<br/> res = false; <br/>}else {<br/> for (INT I = 0; int (answer. size ()> I; ++ I) {<br/> If (answer [I]! = P1 [I]) {<br/> res = false; <br/>}< br/> If (! Res) {<br/> cout <"doesn't match !!!! "<Endl; <br/>} else if (double (endtime-starttime)/clocks_per_sec> = 2) {<br/> cout <"fail the timeout" <Endl; <br/> res = false; <br/>} else if (hasanswer) {<br/> cout <"Match :-)" <Endl; <br/>}else {<br/> cout <"OK, but is it right? "<Endl; <br/>}< br/> cout <" "<Endl; <br/> return res; <br/>}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.