Skip to content

Commit df2ddfc

Browse files
committed
srm 639 div2 250
1 parent 56f4f3a commit df2ddfc

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

ElectronicPetEasy.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#include <iostream>
2+
#include <sstream>
3+
#include <set>
4+
#include <vector>
5+
#include <map>
6+
#include <algorithm>
7+
using namespace std;
8+
9+
class ElectronicPetEasy{
10+
public:
11+
string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2) {
12+
int m1 = 0, m2 = 0;
13+
while(m1 < t1 && m2 < t2){
14+
int i = st1 + p1 * m1, j = st2 + p2*m2;
15+
if(i == j) return "Difficult";
16+
if(i < j) m1++;
17+
else m2++;
18+
}
19+
return "Easy";
20+
}
21+
22+
// BEGIN CUT HERE
23+
public:
24+
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(); if ((Case == -1) || (Case == 3)) test_case_3(); if ((Case == -1) || (Case == 4)) test_case_4(); }
25+
private:
26+
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(); }
27+
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; } }
28+
void test_case_0() { int Arg0 = 3; int Arg1 = 3; int Arg2 = 3; int Arg3 = 5; int Arg4 = 2; int Arg5 = 3; string Arg6 = "Difficult"; verify_case(0, Arg6, isDifficult(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
29+
void test_case_1() { int Arg0 = 3; int Arg1 = 3; int Arg2 = 3; int Arg3 = 5; int Arg4 = 2; int Arg5 = 2; string Arg6 = "Easy"; verify_case(1, Arg6, isDifficult(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
30+
void test_case_2() { int Arg0 = 1; int Arg1 = 4; int Arg2 = 7; int Arg3 = 1; int Arg4 = 4; int Arg5 = 7; string Arg6 = "Difficult"; verify_case(2, Arg6, isDifficult(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
31+
void test_case_3() { int Arg0 = 1; int Arg1 = 1000; int Arg2 = 1000; int Arg3 = 2; int Arg4 = 1000; int Arg5 = 1000; string Arg6 = "Easy"; verify_case(3, Arg6, isDifficult(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
32+
void test_case_4() { int Arg0 = 1; int Arg1 = 1; int Arg2 = 1; int Arg3 = 2; int Arg4 = 2; int Arg5 = 2; string Arg6 = "Easy"; verify_case(4, Arg6, isDifficult(Arg0, Arg1, Arg2, Arg3, Arg4, Arg5)); }
33+
34+
// END CUT HERE
35+
36+
};
37+
38+
// BEGIN CUT HERE
39+
int main(){
40+
41+
ElectronicPetEasy ___test;
42+
___test.run_test(-1);
43+
}
44+
// END CUT HERE

ElectronicPetEasy.txt

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
Kirino has found a game in which she has to feed electronic pets.
3+
There are two pets in the game.
4+
You are given six ints <b>st1</b>,<b>p1</b>,<b>t1</b>,<b>st2</b>,<b>p2</b>,<b>t2</b>.
5+
To win the game, Kirino must satisfy the following rules:
6+
<ul>
7+
<li>She must feed her first pet for the first time precisely at the time <b>st1</b>.</li>
8+
<li>There must be exactly <b>p1</b> seconds between any two consecutive feedings of the first pet.</li>
9+
<li>She must feed the first pet exactly <b>t1</b> times.</li>
10+
<li>She must feed her second pet for the first time precisely at the time <b>st2</b>.</li>
11+
<li>There must be exactly <b>p2</b> seconds between any two consecutive feedings of the second pet.</li>
12+
<li>She must feed the second pet exactly <b>t2</b> times.</li>
13+
</ul>
14+
</p>
15+
16+
<p>
17+
Feeding the pets is easy if Kirino never needs to feed both pets at the same time.
18+
Return "Easy" (quotes for clarity) if feeding the pets is easy for the given inputs.
19+
Otherwise, return "Difficult".
20+
Note that the return value is case-sensitive.
21+
</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>ElectronicPetEasy</td></tr><tr><td>Method:</td><td>isDifficult</td></tr><tr><td>Parameters:</td><td>int, int, int, int, int, int</td></tr><tr><td>Returns:</td><td>string</td></tr><tr><td>Method signature:</td><td>string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)</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>st1</b>, <b>p1</b>, <b>t1</b>, <b>st2</b>, <b>p2</b>, and <b>t2</b> will be between 1 and 1,000, 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>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Difficult&quot;</pre></td></tr><tr><td><table><tr><td colspan="2">Kirino must feed her first pet at the times 3, 6, and 9.
22+
She must feed her second pet at the times 5, 7, and 9.
23+
Feeding these two pets is difficult because she needs to feed both of them at the same time (at time 9).</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>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>3</pre></td></tr><tr><td><pre>5</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Easy&quot;</pre></td></tr><tr><td><table><tr><td colspan="2">Kirino must feed her first pet at 3, 6, and 9, and her second pet at 5 and 7.
24+
As all of these times are distinct, feeding these two pets is easy.</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>1</pre></td></tr><tr><td><pre>4</pre></td></tr><tr><td><pre>7</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>4</pre></td></tr><tr><td><pre>7</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Difficult&quot;</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">3)</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>1000</pre></td></tr><tr><td><pre>1000</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>1000</pre></td></tr><tr><td><pre>1000</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Easy&quot;</pre></td></tr><tr><td><table><tr><td colspan="2"></td></tr></table></td></tr></table></td></tr><tr><td align="center" nowrap="true">4)</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><tr><td><pre>1</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>2</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: &quot;Easy&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)