Skip to content

Commit 1404292

Browse files
committed
srm 633 div 2 500
1 parent a11bf59 commit 1404292

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed

Jumping.cpp

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 <cmath>
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 Jumping {
19+
public:
20+
string ableToGet(int x, int y, vector <int> a)
21+
{
22+
double d = sqrt(x*x + y*y);
23+
double sum = accumulate(a.begin(), a.end(), 0);
24+
if(sum < d) return "Not able";
25+
int mx = *max_element(a.begin(), a.end());
26+
if(2*mx - sum > d) return "Not able";
27+
return "Able";
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(); if ((Case == -1) || (Case == 4)) test_case_4(); if ((Case == -1) || (Case == 5)) test_case_5(); if ((Case == -1) || (Case == 6)) test_case_6(); }
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 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; } }
36+
void test_case_0() { int Arg0 = 5; int Arg1 = 4; int Arr2[] = {2, 5}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(0, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
37+
void test_case_1() { int Arg0 = 3; int Arg1 = 4; int Arr2[] = {4}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Not able"; verify_case(1, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
38+
void test_case_2() { int Arg0 = 3; int Arg1 = 4; int Arr2[] = {6}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Not able"; verify_case(2, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
39+
void test_case_3() { int Arg0 = 0; int Arg1 = 1; int Arr2[] = {100, 100}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(3, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
40+
void test_case_4() { int Arg0 = 300; int Arg1 = 400; int Arr2[] = {500}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(4, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
41+
void test_case_5() { int Arg0 = 11; int Arg1 = 12; int Arr2[] = {1,2,3,4,5,6,7,8,9,10}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Able"; verify_case(5, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
42+
void test_case_6() { int Arg0 = 11; int Arg1 = 12; int Arr2[] = {1,2,3,4,5,6,7,8,9,100}; vector <int> Arg2(Arr2, Arr2 + (sizeof(Arr2) / sizeof(Arr2[0]))); string Arg3 = "Not able"; verify_case(6, Arg3, ableToGet(Arg0, Arg1, Arg2)); }
43+
44+
// END CUT HERE
45+
46+
};
47+
48+
// BEGIN CUT HERE
49+
int main(){
50+
51+
Jumping ___test;
52+
___test.run_test(-1);
53+
54+
}
55+
// END CUT HERE

Jumping.txt

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
PROBLEM STATEMENT
2+
Frog Suwako lives on a two-dimensional plane.
3+
She likes to jump.
4+
Currently, she is located in the point (0, 0).
5+
She would like to reach the point (x, y).
6+
You are given the ints x and y.
7+
8+
9+
10+
Suwako wants to reach the desired destination in a specific way: using a series of jumps with pre-determined lengths.
11+
You are given these lengths in a vector <int> jumpLenghts.
12+
For example, if jumpLengths = { 2, 5 }, Suwako must make a jump of length exactly 2, followed by a jump of length exactly 5.
13+
14+
15+
16+
Note that Suwako can jump onto arbitrary points in the plane, they are not required to have integer coordinates.
17+
Return "Able" (quotes for clarity) if Suwako is able to reach her desired destination from (0, 0) using the desired sequence of jump lengths.
18+
Otherwise, return "Not able".
19+
20+
DEFINITION
21+
Class:Jumping
22+
Method:ableToGet
23+
Parameters:int, int, vector <int>
24+
Returns:string
25+
Method signature:string ableToGet(int x, int y, vector <int> jumpLengths)
26+
27+
28+
CONSTRAINTS
29+
-x will be between -1,000 and 1,000, inclusive.
30+
-y will be between -1,000 and 1,000, inclusive.
31+
-len will contain between 1 and 50 elements, inclusive.
32+
-Each element in len will be between 1 and 1,000, inclusive.
33+
34+
35+
EXAMPLES
36+
37+
0)
38+
5
39+
4
40+
{2, 5}
41+
42+
Returns: "Able"
43+
44+
One possibility is to jump from (0, 0) to (2, 0), and then from (2, 0) to (5, 4).
45+
46+
1)
47+
3
48+
4
49+
{4}
50+
51+
Returns: "Not able"
52+
53+
The distance from (0, 0) to (3, 4) is 5. You cannot get there using a single jump of length 4 - it is too short.
54+
55+
2)
56+
3
57+
4
58+
{6}
59+
60+
Returns: "Not able"
61+
62+
The distance from (0, 0) to (3, 4) is 5. You cannot get there using a single jump of length 6 - it is too long.
63+
64+
3)
65+
0
66+
1
67+
{100, 100}
68+
69+
Returns: "Able"
70+
71+
Here, one possible solution looks as follows: Let t = sqrt(100*100 - 0.5*0.5). Suwoko will make her first jump from (0, 0) to (t, 0.5), and her second jump from (t, 0.5) to (0, 1).
72+
73+
4)
74+
300
75+
400
76+
{500}
77+
78+
Returns: "Able"
79+
80+
81+
82+
5)
83+
11
84+
12
85+
{1,2,3,4,5,6,7,8,9,10}
86+
87+
Returns: "Able"
88+
89+
90+
91+
6)
92+
11
93+
12
94+
{1,2,3,4,5,6,7,8,9,100}
95+
96+
Returns: "Not able"
97+
98+

0 commit comments

Comments
 (0)