Skip to content

Commit 39acf5e

Browse files
authored
Add files via upload
1 parent 002b8d7 commit 39acf5e

17 files changed

+811
-0
lines changed

CodeForces/1213A. Chips Moving.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 1e2 + 1;
6+
int n;
7+
8+
int main() {
9+
#ifndef ONLINE_JUDGE
10+
freopen("in", "r", stdin);
11+
#endif
12+
13+
scanf("%d", &n);
14+
int even = 0, odd = 0;
15+
for(int i = 0, tmp; i < n; ++i) {
16+
scanf("%d", &tmp);
17+
if(tmp % 2 == 0) ++even;
18+
else ++odd;
19+
}
20+
21+
if(even == 0 || odd == 0)
22+
puts("0");
23+
else
24+
printf("%d\n", min(odd, even));
25+
26+
return 0;
27+
}

CodeForces/1213B. Bad Prices.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 1e6 + 1;
6+
int t, n, a[N], mn, res;
7+
8+
int main() {
9+
#ifndef ONLINE_JUDGE
10+
freopen("in", "r", stdin);
11+
#endif
12+
13+
scanf("%d", &t);
14+
while(t-- != 0) {
15+
mn = 1e9;
16+
res = 0;
17+
18+
scanf("%d", &n);
19+
for(int i = 0; i < n; ++i)
20+
scanf("%d", a + i);
21+
22+
for(int i = n - 1; i >= 0; --i) {
23+
if(a[i] > mn)
24+
++res;
25+
mn = min(mn, a[i]);
26+
}
27+
28+
printf("%d\n", res);
29+
}
30+
31+
return 0;
32+
}

CodeForces/1213C. Book Reading.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 1e6 + 1;
6+
int q;
7+
long long n, m;
8+
9+
int main() {
10+
#ifndef ONLINE_JUDGE
11+
freopen("in", "r", stdin);
12+
#endif
13+
14+
scanf("%d", &q);
15+
while(q-- != 0) {
16+
scanf("%lld %lld", &n, &m);
17+
18+
if(m > n) {
19+
puts("0");
20+
continue;
21+
}
22+
23+
vector<int> all;
24+
for(long long i = m; i <= n; i += m) {
25+
if(i != m && all[0] == i % 10)
26+
break;
27+
all.push_back(i % 10);
28+
}
29+
30+
long long res = 0;
31+
for(int i = 0; i < all.size(); ++i)
32+
res += all[i];
33+
34+
long long mm = m * all.size();
35+
res = n / mm * res;
36+
long long rem = n % mm;
37+
for(int i = 0; i < all.size(); ++i) {
38+
if(rem - m < 0)
39+
break;
40+
res += all[i];
41+
rem -= m;
42+
}
43+
printf("%lld\n", res);
44+
}
45+
46+
return 0;
47+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 2e5 + 10;
6+
int n, k, a[N], fr[N], frp[N];
7+
8+
int main() {
9+
#ifndef ONLINE_JUDGE
10+
freopen("in", "r", stdin);
11+
#endif
12+
13+
scanf("%d %d", &n, &k);
14+
for(int i = 0; i < n; ++i)
15+
scanf("%d", a + i);
16+
sort(a, a + n);
17+
18+
int res = 1e9;
19+
for(int i = 0; i < n; ++i) {
20+
int cur = a[i], cnt = 0;
21+
while(cur >= 0) {
22+
++fr[cur];
23+
frp[cur] += cnt;
24+
if(fr[cur] >= k)
25+
res = min(res, frp[cur]);
26+
if(cur == 0)
27+
break;
28+
cur /= 2;
29+
++cnt;
30+
}
31+
}
32+
33+
printf("%d\n", res);
34+
35+
return 0;
36+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 2e5 + 10;
6+
int n, k, a[N], fr[N], frp[N];
7+
8+
int main() {
9+
#ifndef ONLINE_JUDGE
10+
freopen("in", "r", stdin);
11+
#endif
12+
13+
scanf("%d %d", &n, &k);
14+
for(int i = 0; i < n; ++i)
15+
scanf("%d", a + i);
16+
sort(a, a + n);
17+
18+
int res = 1e9;
19+
for(int i = 0; i < n; ++i) {
20+
int cur = a[i], cnt = 0;
21+
while(cur >= 0) {
22+
++fr[cur];
23+
frp[cur] += cnt;
24+
if(fr[cur] >= k)
25+
res = min(res, frp[cur]);
26+
if(cur == 0)
27+
break;
28+
cur /= 2;
29+
++cnt;
30+
}
31+
}
32+
33+
printf("%d\n", res);
34+
35+
return 0;
36+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int n;
6+
string s, t;
7+
8+
int main() {
9+
#ifndef ONLINE_JUDGE
10+
freopen("in", "r", stdin);
11+
#endif
12+
13+
scanf("%d", &n);
14+
cin >> s >> t;
15+
16+
string per = "abc";
17+
18+
do {
19+
string res;
20+
21+
res = "";
22+
for(int i = 0; i < n; ++i)
23+
res += per;
24+
if(res.find(s) == string::npos && res.find(t) == string::npos) {
25+
cout << "YES" << endl << res << endl;
26+
return 0;
27+
}
28+
29+
res = "";
30+
for(int i = 0; i < 3; ++i)
31+
for(int j = 0; j < n; ++j)
32+
res += per[i];
33+
if(res.find(s) == string::npos && res.find(t) == string::npos) {
34+
cout << "YES" << endl << res << endl;
35+
return 0;
36+
}
37+
} while(next_permutation(per.begin(), per.end()));
38+
39+
puts("NO");
40+
41+
return 0;
42+
}

CodeForces/1216A. Prefixes.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 2e5 + 10;
6+
int n;
7+
char s[N];
8+
9+
int main() {
10+
#ifndef ONLINE_JUDGE
11+
freopen("in", "r", stdin);
12+
#endif
13+
14+
scanf("%d\n%s", &n, s);
15+
int len = strlen(s);
16+
17+
int res = 0, a = 0, b = 0;
18+
for(int i = 0; i < n; ++i) {
19+
if(s[i] == 'a')
20+
++a;
21+
if(s[i] == 'b')
22+
++b;
23+
if((i + 1) % 2 == 0 && a != b) {
24+
++res;
25+
if(a > b) {
26+
if(s[i] == 'a')
27+
s[i] = 'b';
28+
else
29+
s[i - 1] = 'b';
30+
--a, ++b;
31+
} else {
32+
if(s[i] == 'b')
33+
s[i] = 'a';
34+
else
35+
s[i - 1] = 'a';
36+
--b, ++a;
37+
}
38+
}
39+
}
40+
41+
printf("%d\n", res);
42+
printf("%s\n", s);
43+
44+
return 0;
45+
}

CodeForces/1216B. Shooting.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 1e3 + 10;
6+
int n;
7+
pair<int, int> a[N];
8+
9+
int main() {
10+
#ifndef ONLINE_JUDGE
11+
freopen("in", "r", stdin);
12+
#endif
13+
14+
scanf("%d", &n);
15+
for(int i = 0, tmp; i < n; ++i) {
16+
scanf("%d", &tmp);
17+
a[i].first = tmp;
18+
a[i].second = i;
19+
}
20+
sort(a, a + n);
21+
reverse(a, a + n);
22+
23+
int res = 0;
24+
for(int i = 0; i < n; ++i)
25+
res += (a[i].first * i + 1);
26+
27+
printf("%d\n", res);
28+
for(int i = 0; i < n; ++i) {
29+
if(i != 0) printf(" ");
30+
printf("%d", a[i].second + 1);
31+
}
32+
puts("");
33+
34+
return 0;
35+
}

CodeForces/1216C. White Sheet.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 6;
6+
long long x1[N], y[N], x2[N], y2[N];
7+
8+
long long intersect_area(int rect1, int rect2, int save) {
9+
long long max_x = min(x2[rect1], x2[rect2]);
10+
long long min_x = max(x1[rect1], x1[rect2]);
11+
long long x_diff = max_x - min_x;
12+
13+
long long max_y = max(y[rect1], y[rect2]);
14+
long long min_y = min(y2[rect1], y2[rect2]);
15+
long long y_diff = min_y - max_y;
16+
17+
if(x_diff < 0 || y_diff < 0)
18+
return 0;
19+
20+
x2[save] = max_x;
21+
y2[save] = min_y;
22+
x1[save] = min_x;
23+
y[save] = max_y;
24+
25+
return x_diff * y_diff;
26+
}
27+
28+
long long rectangle_area() {
29+
return (x2[0] - x1[0]) * (y2[0] - y[0]);
30+
}
31+
32+
int main() {
33+
#ifndef ONLINE_JUDGE
34+
freopen("in", "r", stdin);
35+
#endif
36+
37+
for(int i = 0; i < 3; ++i)
38+
scanf("%lld %lld %lld %lld", x1 + i, y + i, x2 + i, y2 + i);
39+
40+
long long _01 = intersect_area(0, 1, 3);
41+
long long _02 = intersect_area(0, 2, 4);
42+
long long _34 = intersect_area(3, 4, 5);
43+
44+
if(_01 == rectangle_area() || _02 == rectangle_area())
45+
puts("NO");
46+
else if(_01 == 0 || _02 == 0)
47+
puts("YES");
48+
else if(_01 + _02 - _34 < rectangle_area())
49+
puts("YES");
50+
else
51+
puts("NO");
52+
53+
return 0;
54+
}

0 commit comments

Comments
 (0)