Skip to content

Commit f184083

Browse files
committed
srm 216 div 1 250
1 parent e1e9241 commit f184083

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

RockStar.cpp

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 vector<int> vi;
14+
typedef vector<vi> vvi;
15+
typedef vector<string> vs;
16+
typedef vector<vs> vvs;
17+
18+
class RockStar{
19+
public:
20+
int getNumSongs(int ff, int fs, int sf, int ss) {
21+
if(fs > sf) return ff + 2*sf + ss + 1;
22+
else if(fs == 0) return ff > 0 ? ff : ss + min(sf, 1);
23+
else return ff + 2*fs + ss;
24+
}
25+
26+
// BEGIN CUT HERE
27+
public:
28+
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(); }
29+
private:
30+
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(); }
31+
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
32+
void test_case_0() { int Arg0 = 100; int Arg1 = 0; int Arg2 = 0; int Arg3 = 200; int Arg4 = 100; verify_case(0, Arg4, getNumSongs(Arg0, Arg1, Arg2, Arg3)); }
33+
void test_case_1() { int Arg0 = 0; int Arg1 = 0; int Arg2 = 20; int Arg3 = 200; int Arg4 = 201; verify_case(1, Arg4, getNumSongs(Arg0, Arg1, Arg2, Arg3)); }
34+
void test_case_2() { int Arg0 = 1; int Arg1 = 2; int Arg2 = 1; int Arg3 = 1; int Arg4 = 5; verify_case(2, Arg4, getNumSongs(Arg0, Arg1, Arg2, Arg3)); }
35+
void test_case_3() { int Arg0 = 192; int Arg1 = 279; int Arg2 = 971; int Arg3 = 249; int Arg4 = 999; verify_case(3, Arg4, getNumSongs(Arg0, Arg1, Arg2, Arg3)); }
36+
37+
// END CUT HERE
38+
39+
};
40+
41+
// BEGIN CUT HERE
42+
int main(){
43+
44+
RockStar ___test;
45+
___test.run_test(-1);
46+
}
47+
// END CUT HERE

RockStar.html

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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>Inspired by the Dire Straits song, &quot;Money for Nothing&quot;, you have decided to become a rock star. After a lengthy recording session, you have acquired:
2+
<ul>
3+
<li> a total of <b>ff</b> songs that start fast and end fast,</li>
4+
<li> a total of <b>fs</b> songs that start fast and end slow,</li>
5+
<li> a total of <b>sf</b> songs that start slow and end fast, and</li>
6+
<li> a total of <b>ss</b> songs that start slow and end slow.</li>
7+
</ul>
8+
It remains only to determine which of these songs should go on your first album, and in what order they should appear. Of course, no song can appear on the album more than once.
9+
<br></br><br></br>
10+
Unfortunately, your record company has placed several restrictions on your album:
11+
<ul>
12+
<li>1. A song that ends fast may only be immediately followed by a song that starts fast.</li>
13+
<li>2. A song that ends slow may only be immediately followed by a song that starts slow.</li>
14+
<li>3. If you have at least one song that starts fast, then the first song on the album must start fast. Otherwise, this restriction can be ignored.</li>
15+
</ul>
16+
At this stage in your artistic career, you must do what your record company has ordered, but you do want to place as many songs as possible on the album.
17+
<br></br><br></br>
18+
Given ints <b>ff</b>, <b>fs</b>, <b>sf</b>, and <b>ss</b>, representing the quantities described above, return the maximum number of songs that can be placed on a single album without violating the record company's restrictions.
19+
</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>RockStar</td></tr><tr><td>Method:</td><td>getNumSongs</td></tr><tr><td>Parameters:</td><td>int, int, int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int getNumSongs(int ff, int fs, int sf, int ss)</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>64</td></tr></table></td></tr><tr><td colspan="2"><h3>Constraints</h3></td></tr><tr><td align="center" valign="top">-</td><td><b>ff</b>, <b>fs</b>, <b>sf</b>, and <b>ss</b> will each be between 0 and 1000 inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>At least one of <b>ff</b>, <b>fs</b>, <b>sf</b> or <b>ss</b> will be greater than 0.</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>100</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>200</pre></td></tr></table></td></tr><tr><td><pre>Returns: 100</pre></td></tr><tr><td><table><tr><td colspan="2">You must begin the album with one of your fast songs by the 3rd restriction. By the 1st restriction, each subsequent song must also now start fast.</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>0</pre></td></tr><tr><td><pre>0</pre></td></tr><tr><td><pre>20</pre></td></tr><tr><td><pre>200</pre></td></tr></table></td></tr><tr><td><pre>Returns: 201</pre></td></tr><tr><td><table><tr><td colspan="2">Since you do not have any songs that start fast, you may begin the album with a song that starts slow. You can use 201 songs by first using the 200 songs that start slow and end slow, then finishing the album with one song that starts slow and ends fast.</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>2</pre></td></tr><tr><td><pre>1</pre></td></tr><tr><td><pre>1</pre></td></tr></table></td></tr><tr><td><pre>Returns: 5</pre></td></tr><tr><td></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>192</pre></td></tr><tr><td><pre>279</pre></td></tr><tr><td><pre>971</pre></td></tr><tr><td><pre>249</pre></td></tr></table></td></tr><tr><td><pre>Returns: 999</pre></td></tr><tr><td></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)