Skip to content

Commit 4d09120

Browse files
committed
srm 648 div 2 250
1 parent 6dfb5fe commit 4d09120

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

KitayutaMart2.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 KitayutaMart2{
19+
public:
20+
int numBought(int K, int T) {
21+
T /= K;
22+
int res = 0;
23+
for(int i = 0; i < 30; i++){
24+
if((1<<i) & T) res++;
25+
}
26+
return res;
27+
}
28+
29+
// BEGIN CUT HERE
30+
public:
31+
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(); }
32+
private:
33+
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(); }
34+
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; } }
35+
void test_case_0() { int Arg0 = 100; int Arg1 = 100; int Arg2 = 1; verify_case(0, Arg2, numBought(Arg0, Arg1)); }
36+
void test_case_1() { int Arg0 = 100; int Arg1 = 300; int Arg2 = 2; verify_case(1, Arg2, numBought(Arg0, Arg1)); }
37+
void test_case_2() { int Arg0 = 150; int Arg1 = 1050; int Arg2 = 3; verify_case(2, Arg2, numBought(Arg0, Arg1)); }
38+
void test_case_3() { int Arg0 = 160; int Arg1 = 163680; int Arg2 = 10; verify_case(3, Arg2, numBought(Arg0, Arg1)); }
39+
40+
// END CUT HERE
41+
42+
};
43+
44+
// BEGIN CUT HERE
45+
int main(){
46+
47+
KitayutaMart2 ___test;
48+
___test.run_test(-1);
49+
}
50+
// END CUT HERE

KitayutaMart2.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
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><i>This problem statement contains superscripts that may not display properly outside the applet.</i></p>
2+
<p></p>
3+
<p>Kitayuta Mart is the largest supermarket in Shuseki Kingdom, offering a great variety of food and household products. The main products are fruits, especially apples. The price system is a little special: the <i>original price</i> of an apple is <b>K</b> yen (the currency of the kingdom). However, if a customer wants to buy more than one apple, the second apple will cost 2*<b>K</b> yen, the third apple will cost 2<sup>2</sup>*<b>K</b> yen, and so on. In general, if a customer is buying <i>n</i> apples, the <i>actual price</i> of the <i>i</i>-th (1 &lt;= <i>i</i> &lt;= <i>n</i>) apple will be 2<sup><i>i</i>-1</sup>*<b>K</b> yen.</p>
4+
<p></p>
5+
<p>Lun the dog loves apples. She has just bought some number of apples at Kitayuta Mart. The prices of those apples were calculated using the above formula. The total she paid for her apples was <b>T</b> yen. You are given two ints: <b>K</b> and <b>T</b>. Find and return the number of the apples that Lun has bought. It is guaranteed that <b>K</b> and <b>T</b> are such that the answer exists and is unique.</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>KitayutaMart2</td></tr><tr><td>Method:</td><td>numBought</td></tr><tr><td>Parameters:</td><td>int, int</td></tr><tr><td>Returns:</td><td>int</td></tr><tr><td>Method signature:</td><td>int numBought(int K, int T)</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>K</b> will be between 80 and 160, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td><b>T</b> will be between 80 and 163,680, inclusive.</td></tr><tr><td align="center" valign="top">-</td><td>The input will be such that the answer exists and is unique.</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>100</pre></td></tr></table></td></tr><tr><td><pre>Returns: 1</pre></td></tr><tr><td><table><tr><td colspan="2">If she buys only one apple, the price will just be <b>K</b> yen.</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>100</pre></td></tr><tr><td><pre>300</pre></td></tr></table></td></tr><tr><td><pre>Returns: 2</pre></td></tr><tr><td><table><tr><td colspan="2">The second apple will cost 2*100 = 200 yen, for the total price of 100 + 200 = 300 yen.</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>150</pre></td></tr><tr><td><pre>1050</pre></td></tr></table></td></tr><tr><td><pre>Returns: 3</pre></td></tr><tr><td><table><tr><td colspan="2">150 + 2*150 + 2<sup>2</sup>*150 = 150 + 300 + 600 = 1050.</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>160</pre></td></tr><tr><td><pre>163680</pre></td></tr></table></td></tr><tr><td><pre>Returns: 10</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)