Skip to content

Commit 2609b82

Browse files
committed
srm 644 div 2 250
1 parent b6a82bb commit 2609b82

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

OkonomiyakiShop.cpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 OkonomiyakiShop{
19+
public:
20+
int count(vector <int> osize, int K) {
21+
sort(osize.begin(), osize.end());
22+
int res = 0;
23+
for(int i = 0; i < osize.size(); i++){
24+
for(int j = i+1; j < osize.size(); j++)
25+
if(osize[j]-osize[i] <= K) res++;
26+
}
27+
return res;
28+
}
29+
30+
// BEGIN CUT HERE
31+
public:
32+
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(); }
33+
private:
34+
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(); }
35+
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; } }
36+
void test_case_0() { int Arr0[] = {1,4,6,7,9}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; int Arg2 = 6; verify_case(0, Arg2, count(Arg0, Arg1)); }
37+
void test_case_1() { int Arr0[] = {1,1,3,3,3}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 2; int Arg2 = 10; verify_case(1, Arg2, count(Arg0, Arg1)); }
38+
void test_case_2() { int Arr0[] = {1,5,9,14,20}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 3; int Arg2 = 0; verify_case(2, Arg2, count(Arg0, Arg1)); }
39+
void test_case_3() { int Arr0[] = {7,2,6,3,4,2,7,8,3,4,9,1,8,4,3,7,5,2,1,9,9,4,5}; vector <int> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[0]))); int Arg1 = 6; int Arg2 = 234; verify_case(3, Arg2, count(Arg0, Arg1)); }
40+
41+
// END CUT HERE
42+
43+
};
44+
45+
// BEGIN CUT HERE
46+
int main(){
47+
48+
OkonomiyakiShop ___test;
49+
___test.run_test(-1);
50+
}
51+
// END CUT HERE

OkonomiyakiShop.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>Cat Snuke and Wolf Sothe came to an okonomiyaki restaurant.
2+
(Okonomiyaki is a Japanese pancake.)
3+
The restaurant makes several types of okonomiyaki.
4+
Each type of okonomiyaki has its specific size.
5+
You are given the sizes of all okonomiyaki types as a vector &lt;int&gt; <b>osize</b>.<br></br><br></br>
6+
7+
The restaurant offers a discount if you order a meal for two persons.
8+
Each such order must consist of two okonomiyakis of different types.
9+
Additionally, the sizes of the two okonomiyakis must differ by <b>K</b> or less.<br></br><br></br>
10+
11+
You are given the vector &lt;int&gt; <b>osize</b> and the int <b>K</b>.
12+
Compute and return the number of different two-person meals offered by the restaurant.</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>OkonomiyakiShop</td></tr><tr><td>Method:</td><td>count</td></tr><tr><td>Parameters:</td><td>vector &lt;int&gt;, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int count(vector &lt;int&gt; osize, int K)</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><tr><td>Stack 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>osize</b> will contain between 2 and 50 elements, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>Each element in <b>osize</b> will be between 1 and 10,000, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>K</b> will be between 1 and 10,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>{1,4,6,7,9}</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: 6</pre></td></tr><tr><td><table><tr><td colspan="2">There are five types of okonomiyaki.
13+
Let's call them types A, B, C, D, and E.
14+
(Type A has size 1, type B has size 4, and so on.)
15+
There are 6 valid two-person meals: A+B, B+C, B+D, C+D, C+E, and D+E.<br></br><br></br>
16+
17+
Note that B+A is the same order as A+B: you get one pancake of type A and one pancake of type B.</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,1,3,3,3}</pre></td></tr><tr><td><pre>2</pre></td></tr></table></td></tr><tr><td><pre>Returns: 10</pre></td></tr><tr><td><table><tr><td colspan="2">Different types of okonomiyaki may have equal sizes.
18+
A two-person meal may contain two okonomiyaki of the same size, they are only required to have a different type.
19+
Therefore, in this test case each pair of different okonomiyaki can be ordered as a two-person meal.</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,5,9,14,20}</pre></td></tr><tr><td><pre>3</pre></td></tr></table></td></tr><tr><td><pre>Returns: 0</pre></td></tr><tr><td><table><tr><td colspan="2">In this test case there is no valid two-person meal: the differences in pancake sizes are all greater than <b>K</b>.</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>{7,2,6,3,4,2,7,8,3,4,9,1,8,4,3,7,5,2,1,9,9,4,5}</pre></td></tr><tr><td><pre>6</pre></td></tr></table></td></tr><tr><td><pre>Returns: 234</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)