Created
April 23, 2010 17:36
-
-
Save sarcilav/376859 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| #include <limits.h> | |
| #include <assert.h> | |
| #include <stdarg.h> | |
| #include <string> | |
| #include <sstream> | |
| #include <iostream> | |
| #include <fstream> | |
| #include <iterator> | |
| #include <algorithm> | |
| #include <vector> | |
| #include <deque> | |
| #include <list> | |
| #include <queue> | |
| #include <stack> | |
| #include <set> | |
| #include <map> | |
| #include <bitset> | |
| using namespace std; | |
| /* DEBUG */ | |
| #define D(x) cerr<<__LINE__<<" "#x" "<<x<<endl | |
| #define D_v(x) for(int i=0;i<x.size();cerr<<x[i++]<<" ") | |
| #define ALL(x) x.begin(),x.end() | |
| // BEGIN CUT HERE | |
| vector<string> split( const string& s, const string& delim =" " ) { | |
| vector<string> res; | |
| string t; | |
| for ( int i = 0 ; i != s.size() ; i++ ) { | |
| if ( delim.find( s[i] ) != string::npos ) { | |
| if ( !t.empty() ) { | |
| res.push_back( t ); | |
| t = ""; | |
| } | |
| } else { | |
| t += s[i]; | |
| } | |
| } | |
| if ( !t.empty() ) { | |
| res.push_back(t); | |
| } | |
| return res; | |
| } | |
| vector<int> splitInt( const string& s, const string& delim =" " ) { | |
| vector<string> tok = split( s, delim ); | |
| vector<int> res; | |
| for ( int i = 0 ; i != tok.size(); i++ ) | |
| res.push_back( atoi( tok[i].c_str() ) ); | |
| return res; | |
| } | |
| // END CUT HERE | |
| // BEGIN CUT HERE | |
| #define ARRSIZE(x) (sizeof(x)/sizeof(x[0])) | |
| template<typename T> void print( T a ) { | |
| cerr << a; | |
| } | |
| static void print( long long a ) { | |
| cerr << a << "L"; | |
| } | |
| static void print( string a ) { | |
| cerr << '"' << a << '"'; | |
| } | |
| template<typename T> void print( vector<T> a ) { | |
| cerr << "{"; | |
| for ( int i = 0 ; i != a.size() ; i++ ) { | |
| if ( i != 0 ) cerr << ", "; | |
| print( a[i] ); | |
| } | |
| cerr << "}" << endl; | |
| } | |
| template<typename T> void eq( int n, T have, T need ) { | |
| if ( have == need ) { | |
| cerr << "Case " << n << " passed." << endl; | |
| } else { | |
| cerr << "Case " << n << " failed: expected "; | |
| print( need ); | |
| cerr << " received "; | |
| print( have ); | |
| cerr << "." << endl; | |
| } | |
| } | |
| template<typename T> void eq( int n, vector<T> have, vector<T> need ) { | |
| if( have.size() != need.size() ) { | |
| cerr << "Case " << n << " failed: returned " << have.size() << " elements; expected " << need.size() << " elements."; | |
| print( have ); | |
| print( need ); | |
| return; | |
| } | |
| for( int i= 0; i < have.size(); i++ ) { | |
| if( have[i] != need[i] ) { | |
| cerr << "Case " << n << " failed. Expected and returned array differ in position " << i << "."; | |
| print( have ); | |
| print( need ); | |
| return; | |
| } | |
| } | |
| cerr << "Case " << n << " passed." << endl; | |
| } | |
| static void eq( int n, string have, string need ) { | |
| if ( have == need ) { | |
| cerr << "Case " << n << " passed." << endl; | |
| } else { | |
| cerr << "Case " << n << " failed: expected "; | |
| print( need ); | |
| cerr << " received "; | |
| print( have ); | |
| cerr << "." << endl; | |
| } | |
| } | |
| // END CUT HERE | |
| class RoadOrFlightEasy { | |
| public: | |
| int minTime(int N, vector <int> roadTime, vector <int> flightTime, int K) { | |
| int ans; | |
| (>>>POINT<<<) | |
| return ans; | |
| } | |
| }; | |
| //g++ RoadOrFlightEasy.cpp -Wall -g -o RoadOrFlightEasy && ./RoadOrFlightEasy | |
| // BEGIN CUT HERE | |
| int main( int argc, char* argv[] ) { | |
| { | |
| int roadTimeARRAY[] = {4, 6, 7}; | |
| vector <int> roadTime( roadTimeARRAY, roadTimeARRAY+ARRSIZE(roadTimeARRAY) ); | |
| int flightTimeARRAY[] = {1, 2, 3}; | |
| vector <int> flightTime( flightTimeARRAY, flightTimeARRAY+ARRSIZE(flightTimeARRAY) ); | |
| RoadOrFlightEasy theObject; | |
| eq(0, theObject.minTime(3, roadTime, flightTime, 1),13); | |
| } | |
| { | |
| int roadTimeARRAY[] = {4, 6, 7}; | |
| vector <int> roadTime( roadTimeARRAY, roadTimeARRAY+ARRSIZE(roadTimeARRAY) ); | |
| int flightTimeARRAY[] = {1, 2, 3}; | |
| vector <int> flightTime( flightTimeARRAY, flightTimeARRAY+ARRSIZE(flightTimeARRAY) ); | |
| RoadOrFlightEasy theObject; | |
| eq(1, theObject.minTime(3, roadTime, flightTime, 2),9); | |
| } | |
| { | |
| int roadTimeARRAY[] = {4, 6, 7}; | |
| vector <int> roadTime( roadTimeARRAY, roadTimeARRAY+ARRSIZE(roadTimeARRAY) ); | |
| int flightTimeARRAY[] = {1, 2, 3}; | |
| vector <int> flightTime( flightTimeARRAY, flightTimeARRAY+ARRSIZE(flightTimeARRAY) ); | |
| RoadOrFlightEasy theObject; | |
| eq(2, theObject.minTime(3, roadTime, flightTime, 3),6); | |
| } | |
| { | |
| int roadTimeARRAY[] = {1, 2, 3}; | |
| vector <int> roadTime( roadTimeARRAY, roadTimeARRAY+ARRSIZE(roadTimeARRAY) ); | |
| int flightTimeARRAY[] = {2, 3, 4}; | |
| vector <int> flightTime( flightTimeARRAY, flightTimeARRAY+ARRSIZE(flightTimeARRAY) ); | |
| RoadOrFlightEasy theObject; | |
| eq(3, theObject.minTime(3, roadTime, flightTime, 2),6); | |
| } | |
| { | |
| int roadTimeARRAY[] = {50, 287, 621, 266, 224, 68, 636}; | |
| vector <int> roadTime( roadTimeARRAY, roadTimeARRAY+ARRSIZE(roadTimeARRAY) ); | |
| int flightTimeARRAY[] = {797, 661, 644, 102, 114, 452, 420}; | |
| vector <int> flightTime( flightTimeARRAY, flightTimeARRAY+ARRSIZE(flightTimeARRAY) ); | |
| RoadOrFlightEasy theObject; | |
| eq(4, theObject.minTime(7, roadTime, flightTime, 2),1772); | |
| } | |
| return 0; | |
| } | |
| // END CUT HERE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment