Skip to content

Commit 6484d88

Browse files
committed
Bits Jaipur 2015 250
1 parent c905efc commit 6484d88

File tree

2 files changed

+67
-0
lines changed

2 files changed

+67
-0
lines changed

TaroBalls.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <iostream>
2+
#include <sstream>
3+
#include <vector>
4+
#include <algorithm>
5+
#include <set>
6+
#include <map>
7+
#include <queue>
8+
#include <cstring>
9+
#include <climits>
10+
#include <cstdio>
11+
using namespace std;
12+
typedef pair<int,int> pi;
13+
typedef set<int> si;
14+
typedef vector<int> vi;
15+
typedef vector<vi> vvi;
16+
typedef vector<string> vs;
17+
18+
class TaroBalls{
19+
public:
20+
string getWinner(int R, int B) {
21+
if(R == B) return "Friend";
22+
return "Taro";
23+
}
24+
25+
// BEGIN CUT HERE
26+
public:
27+
void run_test(int Case) { if ((Case == -1) || (Case == 0)) test_case_0(); if ((Case == -1) || (Case == 1)) test_case_1(); if ((Case == -1) || (Case == 2)) test_case_2(); }
28+
private:
29+
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
30+
void verify_case(int Case, const string &Expected, const string &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
31+
void test_case_0() { int Arg0 = 1; int Arg1 = 2; string Arg2 = "Taro"; verify_case(0, Arg2, getWinner(Arg0, Arg1)); }
32+
void test_case_1() { int Arg0 = 1; int Arg1 = 1; string Arg2 = "Friend"; verify_case(1, Arg2, getWinner(Arg0, Arg1)); }
33+
void test_case_2() { int Arg0 = 4; int Arg1 = 7; string Arg2 = "Taro"; verify_case(2, Arg2, getWinner(Arg0, Arg1)); }
34+
35+
// END CUT HERE
36+
37+
};
38+
39+
// BEGIN CUT HERE
40+
int main(){
41+
42+
TaroBalls ___test;
43+
___test.run_test(-1);
44+
}
45+
// END CUT HERE

TaroBalls.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<html><body bgcolor="#000000" text="#ffffff"><table><tr><td colspan="2"><h3>Problem Statement</h3></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><p>
2+
Cat Taro has a box with exactly <b>R</b> red balls and <b>B</b> blue balls inside.
3+
He and his friend decided to play the following game.
4+
</p>
5+
<p>
6+
</p>
7+
<p>
8+
Players take alternate turns, Taro goes first.
9+
In each turn, the current player should take exactly one ball from the box.
10+
The only constraint is that the color of the ball he took must be different from the color of the previously taken ball (i.e., the one taken by the opponent in the immediately preceding turn).
11+
(Note that in the first turn Taro can take a ball of any color.)
12+
The player that cannot take a valid turn loses.
13+
Both players play optimally.
14+
</p>
15+
<p>
16+
</p>
17+
<p>
18+
You are given the two ints <b>R</b> and <b>B</b>. Return "Taro" if Taro wins the game and "Friend" otherwise (quotes for clarity).
19+
</p></td></tr><tr><td colspan="2"><h3>Definition</h3></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td>Class:</td><td>TaroBalls</td></tr><tr><td>Method:</td><td>getWinner</td></tr><tr><td>Parameters:</td><td>int, int</td></tr><tr><td>Returns:</td><td>string</td></tr><tr><td>Method signature:</td><td>string getWinner(int R, int B)</td></tr><tr><td colspan="2">(be sure your method is public)</td></tr></table></td></tr><tr><td colspan="2"><h3>Limits</h3></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td>Time limit (s):</td><td>2.000</td></tr><tr><td>Memory limit (MB):</td><td>256</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>R</b> and <b>B</b> will be between 1 and 1000, inclusive.</td></tr><tr><td colspan="2"><h3>Examples</h3></td></tr><tr><td align="center" nowrap="true">0)</td><td></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td><table><tr><td><pre>1</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Taro&quot;</pre></td></tr><tr><td><table><tr><td colspan="2">The best bet for Taro is to start with a blue ball. Then his friend will have to take a red ball, after which Taro will again take a blue one. There is no ball left for the friend. Thus, the winner is Taro.
20+
<p>
21+
</p>
22+
<img src="http://s4.postimg.org/f21sq1lnx/image00.png"></img></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">1)</td><td></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td><table><tr><td><pre>1</pre></td></tr><tr><td><pre>1</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Friend&quot;</pre></td></tr><tr><td><table><tr><td colspan="2">Taro loses in this case.</td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">2)</td><td></td></tr><tr><td>&#160;&#160;&#160;&#160;</td><td><table><tr><td><table><tr><td><pre>4</pre></td></tr><tr><td><pre>7</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Taro&quot;</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr></table><p>This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved. </p></body></html>

0 commit comments

Comments
 (0)