Skip to content

Commit 5937d49

Browse files
committed
Done CodeForces Round 630(div2) 2 questions
1 parent 2d7a43c commit 5937d49

File tree

4 files changed

+200
-1
lines changed

4 files changed

+200
-1
lines changed

Codeforces/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
set(FOLDER_NAME Round629_div3)
1+
set(FOLDER_NAME Round630_div2)
22

33
add_executable(A ${FOLDER_NAME}/A.cpp)
44
add_executable(B ${FOLDER_NAME}/B.cpp)
55
add_executable(C ${FOLDER_NAME}/C.cpp)
6+
add_executable(D ${FOLDER_NAME}/D.cpp)
67
add_executable(solving ${FOLDER_NAME}/solving.cpp)

Codeforces/Round630_div2/A.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//
2+
// Created by 10578 on 3/31/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+
18+
int main() {
19+
BOOST_IO;
20+
21+
#ifdef LOCAL
22+
ALTER_IN("../in.txt");
23+
#endif
24+
25+
int T;
26+
cin >> T;
27+
int a, b, c, d;
28+
int x, y, x1, y1, x2, y2;
29+
while (T--) {
30+
cin >> a >> b >> c >> d;
31+
cin >> x >> y >> x1 >> y1 >> x2 >> y2;
32+
33+
int horizontal = b - a;
34+
int vertical = d - c;
35+
36+
if (y2 - y == 0 && vertical > 0 ||
37+
y1 - y == 0 && vertical < 0 ||
38+
x2 - x == 0 && horizontal > 0 ||
39+
x1 - x == 0 && horizontal < 0) {
40+
cout << "NO" << endl;
41+
continue;
42+
}
43+
44+
int result_x = x + horizontal;
45+
int result_y = y + vertical;
46+
bool result = !(result_x > x2 || result_x < x1 || result_y > y2 || result_y < y1);
47+
48+
if (result) {
49+
if (y2 - y == 0 && y1 - y == 0 && c != 0 && d != 0 ||
50+
x2 - x == 0 && x1 - x == 0 && a != 0 && b != 0) {
51+
result = false;
52+
}
53+
}
54+
55+
cout << (result ? "YES" : "NO") << endl;
56+
}
57+
58+
return 0;
59+
}

Codeforces/Round630_div2/B.cpp

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
//
2+
// Created by 10578 on 3/31/2020.
3+
//
4+
5+
#include <vector>
6+
#include <iostream>
7+
#include <fstream>
8+
#include <numeric>
9+
#include <algorithm>
10+
#include <iterator>
11+
#include <set>
12+
#include <map>
13+
14+
#define BOOST_IO ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
15+
#define ALTER_IN(name) fstream _in(name); cin.rdbuf(_in.rdbuf());
16+
//#define LOCAL
17+
18+
using namespace std;
19+
20+
21+
int get_divisor(int n) {
22+
for (int i = 2; i <= (n >> 1); ++i) {
23+
if (n % i == 0) {
24+
return i;
25+
}
26+
}
27+
28+
return 1;
29+
}
30+
31+
void solve(int n, vector<int> &v) {
32+
set<int> color_set;
33+
vector<int> dividers(v.size());
34+
35+
for (int i = 0; i < v.size(); ++i) {
36+
dividers[i] = get_divisor(v[i]);
37+
color_set.insert(dividers[i]);
38+
}
39+
40+
map<int, int> divider_to_color;
41+
int color = 1;
42+
for (auto &&divider : dividers) {
43+
if (divider_to_color.find(divider) == divider_to_color.end()) {
44+
divider_to_color[divider] = color++; // color from 1 - size
45+
}
46+
}
47+
48+
cout << divider_to_color.size() << endl;
49+
50+
for (auto &&x: dividers) {
51+
cout << divider_to_color[x] << " ";
52+
}
53+
cout << endl;
54+
55+
// copy(colors.begin(), colors.end(), ostream_iterator<int>(cout, " "));
56+
}
57+
58+
59+
int main() {
60+
BOOST_IO;
61+
62+
#ifdef LOCAL
63+
ALTER_IN("../in.txt");
64+
#endif
65+
66+
int T = 0;
67+
cin >> T;
68+
int n;
69+
vector<int> v;
70+
while (T--) {
71+
cin >> n;
72+
v.resize(n);
73+
for (int i = 0; i < n; ++i) {
74+
cin >> v[i];
75+
}
76+
77+
solve(n, v);
78+
}
79+
80+
return 0;
81+
}
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/31/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+
}

0 commit comments

Comments
 (0)