Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6b24478

Browse files
committedJan 26, 2014
add two matches
1 parent 4367bf4 commit 6b24478

File tree

6 files changed

+562
-0
lines changed

6 files changed

+562
-0
lines changed
 

‎a.out

-9.62 KB
Binary file not shown.

‎tc/srm567/250.cpp

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
#include <vector>
2+
#include <list>
3+
#include <map>
4+
#include <set>
5+
#include <queue>
6+
#include <deque>
7+
#include <stack>
8+
#include <bitset>
9+
#include <algorithm>
10+
#include <functional>
11+
#include <numeric>
12+
#include <utility>
13+
#include <sstream>
14+
#include <iostream>
15+
#include <iomanip>
16+
#include <cstdio>
17+
#include <cmath>
18+
#include <cstdlib>
19+
#include <ctime>
20+
21+
using namespace std;
22+
const int MAXN = 77777;
23+
24+
typedef long long int ll;
25+
26+
class TheSquareRootDilemma {
27+
public:
28+
int countPairs(int N, int M) {
29+
vector<ll> sq;
30+
for(int i=1; i<=MAXN; i++){
31+
ll tmp = i;
32+
tmp *= i;
33+
sq.push_back(tmp);
34+
}
35+
36+
int sz = sq.size();
37+
int cnt = 0;
38+
for(int i=0; i<sz; i++){
39+
ll A = sq[i];
40+
if(A>N)break;
41+
for(int j=0; j<sz; j++){
42+
ll B = sq[j];
43+
if(B>M)break;
44+
cnt += 1;
45+
cout<<"now "<<A<<" "<<B<<endl;
46+
}
47+
}
48+
return cnt;
49+
}
50+
};
51+
52+
// BEGIN KAWIGIEDIT TESTING
53+
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
54+
bool KawigiEdit_RunTest(int testNum, int p0, int p1, bool hasAnswer, int p2) {
55+
cout << "Test " << testNum << ": [" << p0 << "," << p1;
56+
cout << "]" << endl;
57+
TheSquareRootDilemma *obj;
58+
int answer;
59+
obj = new TheSquareRootDilemma();
60+
clock_t startTime = clock();
61+
answer = obj->countPairs(p0, p1);
62+
clock_t endTime = clock();
63+
delete obj;
64+
bool res;
65+
res = true;
66+
cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
67+
if (hasAnswer) {
68+
cout << "Desired answer:" << endl;
69+
cout << "\t" << p2 << endl;
70+
}
71+
cout << "Your answer:" << endl;
72+
cout << "\t" << answer << endl;
73+
if (hasAnswer) {
74+
res = answer == p2;
75+
}
76+
if (!res) {
77+
cout << "DOESN'T MATCH!!!!" << endl;
78+
} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
79+
cout << "FAIL the timeout" << endl;
80+
res = false;
81+
} else if (hasAnswer) {
82+
cout << "Match :-)" << endl;
83+
} else {
84+
cout << "OK, but is it right?" << endl;
85+
}
86+
cout << "" << endl;
87+
return res;
88+
}
89+
int main() {
90+
bool all_right;
91+
all_right = true;
92+
93+
int p0;
94+
int p1;
95+
int p2;
96+
97+
{
98+
// ----- test 0 -----
99+
p0 = 2;
100+
p1 = 2;
101+
p2 = 2;
102+
all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
103+
// ------------------
104+
}
105+
106+
{
107+
// ----- test 1 -----
108+
p0 = 10;
109+
p1 = 1;
110+
p2 = 3;
111+
all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
112+
// ------------------
113+
}
114+
115+
{
116+
// ----- test 2 -----
117+
p0 = 3;
118+
p1 = 8;
119+
p2 = 5;
120+
all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
121+
// ------------------
122+
}
123+
124+
{
125+
// ----- test 3 -----
126+
p0 = 100;
127+
p1 = 100;
128+
p2 = 310;
129+
all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
130+
// ------------------
131+
}
132+
133+
if (all_right) {
134+
cout << "You're a stud (at least on the example cases)!" << endl;
135+
} else {
136+
cout << "Some of the test cases had errors." << endl;
137+
}
138+
return 0;
139+
}
140+
// END KAWIGIEDIT TESTING

‎tc/srm567/a.out

25.6 KB
Binary file not shown.

‎tc/srm568/250.cpp

+212
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,212 @@
1+
#include <vector>
2+
#include <list>
3+
#include <map>
4+
#include <set>
5+
#include <queue>
6+
#include <deque>
7+
#include <stack>
8+
#include <bitset>
9+
#include <algorithm>
10+
#include <functional>
11+
#include <numeric>
12+
#include <utility>
13+
#include <sstream>
14+
#include <iostream>
15+
#include <iomanip>
16+
#include <cstdio>
17+
#include <cmath>
18+
#include <cstdlib>
19+
#include <ctime>
20+
21+
using namespace std;
22+
23+
const int MAXN = 500;
24+
int min_p[MAXN];
25+
int sum_d[MAXN];
26+
#define pii pair<int, int>
27+
const int INF = 2100000000;
28+
29+
class BallsSeparating {
30+
public:
31+
int get_sum(int a, int b, int c, vector<int> red, vector<int> green, vector<int> blue, int sz){
32+
int tmp=0;
33+
for(int i=0; i<sz; i++){
34+
if(i==a || i==b||i==c)continue;
35+
tmp += min_p[i];
36+
}
37+
return tmp;
38+
}
39+
40+
int minOperations(vector <int> red, vector <int> green, vector <int> blue) {
41+
42+
int sz = red.size();
43+
if(sz<3){
44+
return -1;
45+
}
46+
47+
vector< pii > sorted_d;
48+
for(int i=0; i<sz; i++){
49+
int tmp = 0;
50+
min_p[i] = min(min( red[i]+green[i], red[i]+blue[i]), blue[i] + green[i]);
51+
}
52+
53+
int final_answer = INF;
54+
for(int i=0; i<sz; i++){
55+
for(int j=0; j<sz; j++){
56+
for(int k=0; k<sz; k++){
57+
if(i==j || j==k || i==k)continue;
58+
cout<<i<<" "<<j<<" "<<k <<endl;
59+
int tmp_ans = green[i] + blue[i] + red[j] + blue[j] + red[k] + green[k]+ get_sum(i, j, k, red, green, blue, sz);
60+
final_answer = min(tmp_ans, final_answer);
61+
}
62+
}
63+
}
64+
return final_answer;
65+
66+
67+
68+
69+
return 0;
70+
}
71+
};
72+
73+
// BEGIN KAWIGIEDIT TESTING
74+
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
75+
bool KawigiEdit_RunTest(int testNum, vector <int> p0, vector <int> p1, vector <int> p2, bool hasAnswer, int p3) {
76+
cout << "Test " << testNum << ": [" << "{";
77+
for (int i = 0; int(p0.size()) > i; ++i) {
78+
if (i > 0) {
79+
cout << ",";
80+
}
81+
cout << p0[i];
82+
}
83+
cout << "}" << "," << "{";
84+
for (int i = 0; int(p1.size()) > i; ++i) {
85+
if (i > 0) {
86+
cout << ",";
87+
}
88+
cout << p1[i];
89+
}
90+
cout << "}" << "," << "{";
91+
for (int i = 0; int(p2.size()) > i; ++i) {
92+
if (i > 0) {
93+
cout << ",";
94+
}
95+
cout << p2[i];
96+
}
97+
cout << "}";
98+
cout << "]" << endl;
99+
BallsSeparating *obj;
100+
int answer;
101+
obj = new BallsSeparating();
102+
clock_t startTime = clock();
103+
answer = obj->minOperations(p0, p1, p2);
104+
clock_t endTime = clock();
105+
delete obj;
106+
bool res;
107+
res = true;
108+
cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
109+
if (hasAnswer) {
110+
cout << "Desired answer:" << endl;
111+
cout << "\t" << p3 << endl;
112+
}
113+
cout << "Your answer:" << endl;
114+
cout << "\t" << answer << endl;
115+
if (hasAnswer) {
116+
res = answer == p3;
117+
}
118+
if (!res) {
119+
cout << "DOESN'T MATCH!!!!" << endl;
120+
} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
121+
cout << "FAIL the timeout" << endl;
122+
res = false;
123+
} else if (hasAnswer) {
124+
cout << "Match :-)" << endl;
125+
} else {
126+
cout << "OK, but is it right?" << endl;
127+
}
128+
cout << "" << endl;
129+
return res;
130+
}
131+
int main() {
132+
bool all_right;
133+
all_right = true;
134+
135+
vector <int> p0;
136+
vector <int> p1;
137+
vector <int> p2;
138+
int p3;
139+
140+
{
141+
// ----- test 0 -----
142+
int t0[] = {1,1,1};
143+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
144+
int t1[] = {1,1,1};
145+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
146+
int t2[] = {1,1,1};
147+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
148+
p3 = 6;
149+
all_right = KawigiEdit_RunTest(0, p0, p1, p2, true, p3) && all_right;
150+
// ------------------
151+
}
152+
153+
{
154+
// ----- test 1 -----
155+
int t0[] = {5};
156+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
157+
int t1[] = {6};
158+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
159+
int t2[] = {8};
160+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
161+
p3 = -1;
162+
all_right = KawigiEdit_RunTest(1, p0, p1, p2, true, p3) && all_right;
163+
// ------------------
164+
}
165+
166+
{
167+
// ----- test 2 -----
168+
int t0[] = {4,6,5,7};
169+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
170+
int t1[] = {7,4,6,3};
171+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
172+
int t2[] = {6,5,3,8};
173+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
174+
p3 = 37;
175+
all_right = KawigiEdit_RunTest(2, p0, p1, p2, true, p3) && all_right;
176+
// ------------------
177+
}
178+
179+
{
180+
// ----- test 3 -----
181+
int t0[] = {7,12,9,9,7};
182+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
183+
int t1[] = {7,10,8,8,9};
184+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
185+
int t2[] = {8,9,5,6,13};
186+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
187+
p3 = 77;
188+
all_right = KawigiEdit_RunTest(3, p0, p1, p2, true, p3) && all_right;
189+
// ------------------
190+
}
191+
192+
{
193+
// ----- test 4 -----
194+
int t0[] = {842398,491273,958925,849859,771363,67803,184892,391907,256150,75799};
195+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
196+
int t1[] = {268944,342402,894352,228640,903885,908656,414271,292588,852057,889141};
197+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
198+
int t2[] = {662939,340220,600081,390298,376707,372199,435097,40266,145590,505103};
199+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
200+
p3 = 7230607;
201+
all_right = KawigiEdit_RunTest(4, p0, p1, p2, true, p3) && all_right;
202+
// ------------------
203+
}
204+
205+
if (all_right) {
206+
cout << "You're a stud (at least on the example cases)!" << endl;
207+
} else {
208+
cout << "Some of the test cases had errors." << endl;
209+
}
210+
return 0;
211+
}
212+
// END KAWIGIEDIT TESTING

‎tc/srm568/250_dp.cpp

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#include <vector>
2+
#include <list>
3+
#include <map>
4+
#include <set>
5+
#include <queue>
6+
#include <deque>
7+
#include <stack>
8+
#include <bitset>
9+
#include <algorithm>
10+
#include <functional>
11+
#include <numeric>
12+
#include <utility>
13+
#include <sstream>
14+
#include <iostream>
15+
#include <iomanip>
16+
#include <cstdio>
17+
#include <cmath>
18+
#include <cstdlib>
19+
#include <ctime>
20+
21+
using namespace std;
22+
23+
const int MAXN = 500;
24+
#define pii pair<int, int>
25+
const int INF = 2100000000;
26+
int dp[MAXN][10];
27+
int data[MAXN][3];
28+
int sz;
29+
30+
class BallsSeparating {
31+
public:
32+
33+
int get_ans(int pos, int state){
34+
if(dp[pos][state]!=-1){
35+
return dp[pos][state];
36+
}
37+
if(pos == sz){
38+
if(state != (1<<3)-1){
39+
return INF;
40+
}else{
41+
return 0;
42+
}
43+
}
44+
45+
int tmp = INF;
46+
for(int i=0; i<3; i++){
47+
int mask = (1<<i) | state;
48+
int add = data[pos][(i+1)%3] + data[pos][(i+2)%3];
49+
tmp = min(tmp, get_ans(pos+1, mask) + add);
50+
}
51+
dp[pos][state] = tmp;
52+
return tmp;
53+
}
54+
55+
int minOperations(vector <int> red, vector <int> green, vector <int> blue) {
56+
memset(dp, -1, sizeof(dp));
57+
sz = red.size();
58+
for(int i=0; i<red.size(); i++){
59+
data[i][0] = red[i];
60+
data[i][1] = green[i];
61+
data[i][2] = blue[i];
62+
}
63+
int ans = get_ans(0, 0);
64+
if(ans == INF){
65+
return -1;
66+
}return ans;
67+
68+
}
69+
};
70+
71+
// BEGIN KAWIGIEDIT TESTING
72+
// Generated by KawigiEdit 2.1.4 (beta) modified by pivanof
73+
bool KawigiEdit_RunTest(int testNum, vector <int> p0, vector <int> p1, vector <int> p2, bool hasAnswer, int p3) {
74+
cout << "Test " << testNum << ": [" << "{";
75+
for (int i = 0; int(p0.size()) > i; ++i) {
76+
if (i > 0) {
77+
cout << ",";
78+
}
79+
cout << p0[i];
80+
}
81+
cout << "}" << "," << "{";
82+
for (int i = 0; int(p1.size()) > i; ++i) {
83+
if (i > 0) {
84+
cout << ",";
85+
}
86+
cout << p1[i];
87+
}
88+
cout << "}" << "," << "{";
89+
for (int i = 0; int(p2.size()) > i; ++i) {
90+
if (i > 0) {
91+
cout << ",";
92+
}
93+
cout << p2[i];
94+
}
95+
cout << "}";
96+
cout << "]" << endl;
97+
BallsSeparating *obj;
98+
int answer;
99+
obj = new BallsSeparating();
100+
clock_t startTime = clock();
101+
answer = obj->minOperations(p0, p1, p2);
102+
clock_t endTime = clock();
103+
delete obj;
104+
bool res;
105+
res = true;
106+
cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
107+
if (hasAnswer) {
108+
cout << "Desired answer:" << endl;
109+
cout << "\t" << p3 << endl;
110+
}
111+
cout << "Your answer:" << endl;
112+
cout << "\t" << answer << endl;
113+
if (hasAnswer) {
114+
res = answer == p3;
115+
}
116+
if (!res) {
117+
cout << "DOESN'T MATCH!!!!" << endl;
118+
} else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
119+
cout << "FAIL the timeout" << endl;
120+
res = false;
121+
} else if (hasAnswer) {
122+
cout << "Match :-)" << endl;
123+
} else {
124+
cout << "OK, but is it right?" << endl;
125+
}
126+
cout << "" << endl;
127+
return res;
128+
}
129+
int main() {
130+
bool all_right;
131+
all_right = true;
132+
133+
vector <int> p0;
134+
vector <int> p1;
135+
vector <int> p2;
136+
int p3;
137+
138+
{
139+
// ----- test 0 -----
140+
int t0[] = {1,1,1};
141+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
142+
int t1[] = {1,1,1};
143+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
144+
int t2[] = {1,1,1};
145+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
146+
p3 = 6;
147+
all_right = KawigiEdit_RunTest(0, p0, p1, p2, true, p3) && all_right;
148+
// ------------------
149+
}
150+
151+
{
152+
// ----- test 1 -----
153+
int t0[] = {5};
154+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
155+
int t1[] = {6};
156+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
157+
int t2[] = {8};
158+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
159+
p3 = -1;
160+
all_right = KawigiEdit_RunTest(1, p0, p1, p2, true, p3) && all_right;
161+
// ------------------
162+
}
163+
164+
{
165+
// ----- test 2 -----
166+
int t0[] = {4,6,5,7};
167+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
168+
int t1[] = {7,4,6,3};
169+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
170+
int t2[] = {6,5,3,8};
171+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
172+
p3 = 37;
173+
all_right = KawigiEdit_RunTest(2, p0, p1, p2, true, p3) && all_right;
174+
// ------------------
175+
}
176+
177+
{
178+
// ----- test 3 -----
179+
int t0[] = {7,12,9,9,7};
180+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
181+
int t1[] = {7,10,8,8,9};
182+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
183+
int t2[] = {8,9,5,6,13};
184+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
185+
p3 = 77;
186+
all_right = KawigiEdit_RunTest(3, p0, p1, p2, true, p3) && all_right;
187+
// ------------------
188+
}
189+
190+
{
191+
// ----- test 4 -----
192+
int t0[] = {842398,491273,958925,849859,771363,67803,184892,391907,256150,75799};
193+
p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
194+
int t1[] = {268944,342402,894352,228640,903885,908656,414271,292588,852057,889141};
195+
p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
196+
int t2[] = {662939,340220,600081,390298,376707,372199,435097,40266,145590,505103};
197+
p2.assign(t2, t2 + sizeof(t2) / sizeof(t2[0]));
198+
p3 = 7230607;
199+
all_right = KawigiEdit_RunTest(4, p0, p1, p2, true, p3) && all_right;
200+
// ------------------
201+
}
202+
203+
if (all_right) {
204+
cout << "You're a stud (at least on the example cases)!" << endl;
205+
} else {
206+
cout << "Some of the test cases had errors." << endl;
207+
}
208+
return 0;
209+
}
210+
// END KAWIGIEDIT TESTING

‎tc/srm568/a.out

36.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.