Skip to content

Commit c416f77

Browse files
committed
Done Codeforces Round#629 div3
1 parent 5248e3c commit c416f77

File tree

8 files changed

+339
-11
lines changed

8 files changed

+339
-11
lines changed

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,9 @@ add_executable(hard LeetCode/hard/76_MinimumWindowSubstring.cpp)
3131

3232
add_executable(random_test test/cin_test.cpp)
3333

34-
add_executable(A Codeforces/Round627_div3/A.cpp)
35-
add_executable(solving Codeforces/Round627_div3/solving.cpp)
36-
3734
add_executable(interviews Interviews/ShunFeng/NumOfStudyMachine.cpp)
3835

3936
add_subdirectory(study)
40-
add_subdirectory(template)
37+
add_subdirectory(template)
38+
add_subdirectory(KickStart)
39+
add_subdirectory(Codeforces)

Codeforces/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
set(FOLDER_NAME Round629_div3)
2+
3+
add_executable(A ${FOLDER_NAME}/A.cpp)
4+
add_executable(B ${FOLDER_NAME}/B.cpp)
5+
add_executable(C ${FOLDER_NAME}/C.cpp)
6+
add_executable(solving ${FOLDER_NAME}/solving.cpp)

Codeforces/Round629_div3/A.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//
2+
// Created by 10578 on 3/12/2020.
3+
//
4+
5+
#include <vector>
6+
#include <iostream>
7+
#include <fstream>
8+
#include <sstream>
9+
#include <algorithm>
10+
11+
#define BOOST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
12+
#define ALTER_IN(name) fstream _in(name); cin.rdbuf(_in.rdbuf());
13+
//#define LOCAL
14+
15+
using namespace std;
16+
17+
int solve(int a, int b) {
18+
if (a < b) {
19+
return b - a;
20+
}
21+
22+
int temp = b;
23+
while (a > temp) {
24+
temp += b;
25+
}
26+
27+
return temp - a;
28+
}
29+
30+
31+
int main() {
32+
BOOST_IO;
33+
34+
#ifdef LOCAL
35+
ALTER_IN("../in.txt");
36+
#endif
37+
38+
int T;
39+
cin >> T;
40+
int a, b;
41+
while (T--) {
42+
cin >> a >> b;
43+
44+
cout << solve(a, b) << endl;
45+
}
46+
47+
return 0;
48+
}

Codeforces/Round629_div3/B.cpp

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// Created by 10578 on 3/12/2020.
3+
//
4+
5+
#include <vector>
6+
#include <iostream>
7+
#include <fstream>
8+
#include <sstream>
9+
#include <algorithm>
10+
#include <set>
11+
#include <cmath>
12+
13+
#define BOOST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
14+
#define ALTER_IN(name) fstream _in(name); cin.rdbuf(_in.rdbuf());
15+
//#define LOCAL
16+
17+
18+
using namespace std;
19+
using ll = long long;
20+
21+
double newton(int n, int k) {
22+
double x0 = 0;
23+
double y0 = pow(x0, 2) - x0 - 2 * k;
24+
double dx;
25+
double b;
26+
27+
for (int i = 0; i < 100; ++i) {
28+
dx = 2 * k - 1;
29+
b = y0 - dx * x0;
30+
x0 = -b / dx;
31+
y0 = pow(x0, 2) - x0 - 2 * k;
32+
}
33+
34+
ll temp;
35+
if (temp = floor(x0); pow(temp, 2) - temp - 2 * k == 0) {
36+
x0 = temp;
37+
} else if (temp = ceil(x0); pow(temp, 2) - temp - 2 * k == 0) {
38+
x0 = temp;
39+
}
40+
41+
return x0;
42+
}
43+
44+
string solve(int n, int k) {
45+
double root = newton(n, k);
46+
ll first = floor(root);
47+
48+
ll pre = 0;
49+
if (first % 2 == 0) {
50+
pre = first / 2;
51+
pre *= (first - 1);
52+
} else {
53+
pre = (first - 1) / 2;
54+
pre *= first;
55+
}
56+
57+
if (root > first) {
58+
first++;
59+
}
60+
61+
ll second = (k - pre) == 0 ? first - 1 : k - pre;
62+
string result(n, 'a');
63+
result[n - first] = 'b';
64+
result[n - second] = 'b';
65+
66+
return result;
67+
}
68+
69+
70+
int main() {
71+
BOOST_IO;
72+
73+
#ifdef LOCAL
74+
ALTER_IN("../in.txt");
75+
#endif
76+
77+
int T = 0;
78+
cin >> T;
79+
int n, k;
80+
while (T--) {
81+
cin >> n >> k;
82+
83+
cout << solve(n, k) << endl;
84+
}
85+
86+
return 0;
87+
}

Codeforces/Round629_div3/C.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//
2+
// Created by 10578 on 3/12/2020.
3+
//
4+
5+
#include <vector>
6+
#include <iostream>
7+
#include <fstream>
8+
#include <sstream>
9+
#include <algorithm>
10+
#include <set>
11+
12+
#define BOOST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
13+
#define ALTER_IN(name) fstream _in(name); cin.rdbuf(_in.rdbuf());
14+
//#define LOCAL
15+
16+
using namespace std;
17+
18+
pair<string, string> solve(int n, string &s) {
19+
string first(s.size(), ' ');
20+
string second(s.size(), ' ');
21+
22+
bool find_1 = false;
23+
for (int i = 0; i < s.size(); ++i) {
24+
if (s[i] == '0') {
25+
first[i] = '0';
26+
second[i] = '0';
27+
}
28+
29+
if (!find_1) {
30+
if (s[i] == '2') {
31+
first[i] = '1';
32+
second[i] = '1';
33+
} else if (s[i] == '1') {
34+
first[i] = '1';
35+
second[i] = '0';
36+
find_1 = true;
37+
}
38+
} else {
39+
if (s[i] == '2') {
40+
first[i] = '0';
41+
second[i] = '2';
42+
} else if (s[i] == '1') {
43+
first[i] = '0';
44+
second[i] = '1';
45+
}
46+
}
47+
}
48+
49+
return make_pair(first, second);
50+
}
51+
52+
53+
int main() {
54+
BOOST_IO;
55+
56+
#ifdef LOCAL
57+
ALTER_IN("../in.txt");
58+
#endif
59+
60+
int T = 0;
61+
cin >> T;
62+
int n;
63+
string s{};
64+
while (T--) {
65+
cin >> n;
66+
cin >> s;
67+
auto result = solve(n, s);
68+
cout << result.first << endl
69+
<< result.second << endl;
70+
}
71+
72+
return 0;
73+
}

Codeforces/Round629_div3/D.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Created by 10578 on 3/12/2020.
3+
//
4+
5+
#include <vector>
6+
#include <iostream>
7+
#include <fstream>
8+
#include <algorithm>
9+
10+
#define BOOST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
11+
#define ALTER_IN(name) fstream _in(name); cin.rdbuf(_in.rdbuf());
12+
#define LOCAL
13+
14+
using namespace std;
15+
16+
int solve(vector<int> &A, vector<int> &B) {
17+
for (int i = 0; i < B.size(); ++i) {
18+
A[i] -= B[i];
19+
}
20+
21+
int count = 0;
22+
int sz = A.size();
23+
for (int i = 0; i < sz; ++i) {
24+
for (int j = i + 1; j < sz; ++j) {
25+
if (A[i] + A[j] > 0) {
26+
++count;
27+
}
28+
}
29+
}
30+
31+
return count;
32+
}
33+
34+
35+
int main() {
36+
BOOST_IO;
37+
38+
#ifdef LOCAL
39+
ALTER_IN("../in.txt");
40+
#endif
41+
42+
int n = 0;
43+
cin >> n;
44+
vector<int> A(n);
45+
vector<int> B(n);
46+
47+
for (int i = 0; i < n; ++i) {
48+
cin >> A[i];
49+
}
50+
51+
for (int i = 0; i < n; ++i) {
52+
cin >> B[i];
53+
}
54+
55+
cout << solve(A, B) << endl;
56+
57+
return 0;
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// Created by 10578 on 3/12/2020.
3+
//
4+
5+
#include <vector>
6+
#include <iostream>
7+
#include <fstream>
8+
#include <algorithm>
9+
10+
#define BOOST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
11+
#define ALTER_IN(name) fstream _in(name); cin.rdbuf(_in.rdbuf());
12+
#define LOCAL
13+
14+
using namespace std;
15+
16+
int solve(vector<int> &A, vector<int> &B) {
17+
for (int i = 0; i < B.size(); ++i) {
18+
A[i] -= B[i];
19+
}
20+
21+
int count = 0;
22+
int sz = A.size();
23+
for (int i = 0; i < sz; ++i) {
24+
for (int j = i + 1; j < sz; ++j) {
25+
if (A[i] + A[j] > 0) {
26+
++count;
27+
}
28+
}
29+
}
30+
31+
return count;
32+
}
33+
34+
35+
int main() {
36+
BOOST_IO;
37+
38+
#ifdef LOCAL
39+
ALTER_IN("../in.txt");
40+
#endif
41+
42+
int n = 0;
43+
cin >> n;
44+
vector<int> A(n);
45+
vector<int> B(n);
46+
47+
for (int i = 0; i < n; ++i) {
48+
cin >> A[i];
49+
}
50+
51+
for (int i = 0; i < n; ++i) {
52+
cin >> B[i];
53+
}
54+
55+
cout << solve(A, B) << endl;
56+
57+
return 0;
58+
}

in.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
3
2-
4 100
3-
20 90 40 90
4-
4 50
5-
30 30 10 10
6-
3 300
7-
999 999 999
1+
5
2+
10 4
3+
13 9
4+
100 13
5+
123 456
6+
92 46

0 commit comments

Comments
 (0)