Skip to content

Commit a027e8a

Browse files
committed
Solve problems 898A, 898B, 898C and 898E from codeforces
1 parent 2a3bb25 commit a027e8a

File tree

5 files changed

+193
-0
lines changed

5 files changed

+193
-0
lines changed

CodeForces/898A. Rounding.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int n, m, tmp;
6+
7+
int main() {
8+
scanf("%d", &n);
9+
tmp = n;
10+
m = n;
11+
12+
while(n % 10 != 0)
13+
++n;
14+
15+
while(m % 10 != 0)
16+
--m;
17+
18+
if(n - tmp < tmp - m)
19+
printf("%d\n", n);
20+
else
21+
printf("%d\n", m);
22+
23+
return 0;
24+
}
25+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <bits/stdc++.h>
2+
3+
typedef long long ll;
4+
5+
using namespace std;
6+
7+
int n, a, b;
8+
9+
int main() {
10+
scanf("%d %d %d", &n, &a, &b);
11+
12+
for(int i = 0; i <= n; ++i)
13+
if(n - (1ll * a * i) >= 0 && (n - (1ll * a * i)) % b == 0) {
14+
printf("YES\n%d %d\n", i, (n - (1ll * a * i)) / b);
15+
return 0;
16+
}
17+
18+
puts("NO");
19+
20+
return 0;
21+
}
22+

CodeForces/898C. Phone Numbers.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <bits/stdc++.h>
2+
3+
typedef long long ll;
4+
5+
using namespace std;
6+
7+
int n;
8+
map<string, vector<string> > mp;
9+
vector<string> tmp;
10+
set<string> sol;
11+
12+
int main() {
13+
cin >> n;
14+
15+
string name, cur;
16+
int ent;
17+
for(int i = 0; i < n; ++i) {
18+
cin >> name >> ent;
19+
for(int j = 0; j < ent; ++j) {
20+
cin >> cur;
21+
mp[name].push_back(cur);
22+
}
23+
}
24+
25+
cout << mp.size() << endl;
26+
for(map<string, vector<string> >::iterator it = mp.begin(); it != mp.end(); ++it) {
27+
tmp.clear();
28+
tmp = it->second;
29+
30+
sort(tmp.begin(), tmp.end());
31+
tmp.resize(unique(tmp.begin(), tmp.end()) - tmp.begin());
32+
33+
sol.clear();
34+
for(int i = 0; i < (int)tmp.size(); ++i) {
35+
bool ok = true;
36+
for(int j = 0; j < (int)tmp.size(); ++j) {
37+
if(i != j) {
38+
if(tmp[i] == tmp[j])
39+
break;
40+
if(tmp[j].size() > tmp[i].size()) {
41+
bool ok1 = true;
42+
for(int k = tmp[j].size() - 1, l = tmp[i].size() - 1; l >= 0; --k, --l) {
43+
if(tmp[j][k] != tmp[i][l]) {
44+
ok1 = false;
45+
break;
46+
}
47+
}
48+
if(ok1) {
49+
ok = false;
50+
break;
51+
}
52+
}
53+
}
54+
}
55+
if(ok)
56+
sol.insert(tmp[i]);
57+
}
58+
59+
cout << it->first << ' ' << sol.size();
60+
for(set<string>::iterator it = sol.begin(); it != sol.end(); ++it)
61+
cout << ' ' << *it;
62+
cout << endl;
63+
}
64+
65+
return 0;
66+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include <bits/stdc++.h>
2+
3+
typedef long long ll;
4+
5+
using namespace std;
6+
7+
long long const N = 3e5 + 1;
8+
long long n, a[N], mn[N], sqrs[32001], cnt = 0;
9+
bool vis[N];
10+
11+
int main() {
12+
for(int i = 0; i < 32001; ++i)
13+
sqrs[i] = i * i;
14+
15+
scanf("%lld", &n);
16+
for(int i = 0; i < n; ++i) {
17+
scanf("%lld", a + i);
18+
if(binary_search(sqrs, sqrs + 32001, a[i])) {
19+
vis[i] = true;
20+
++cnt;
21+
}
22+
}
23+
24+
if(cnt == n / 2) {
25+
puts("0");
26+
return 0;
27+
}
28+
29+
for(int i = 0, idx; i < n; ++i) {
30+
idx = lower_bound(sqrs, sqrs + 32001, a[i]) - sqrs;
31+
if(idx < 32001 && sqrs[idx] == a[i])
32+
mn[i] = 0;
33+
else {
34+
long long after = 2e16, before = 2e16;
35+
if(idx < 32001)
36+
after = abs(sqrs[idx] - a[i]);
37+
38+
if(idx - 1 >= 0)
39+
before = abs(a[i] - sqrs[idx - 1]);
40+
41+
mn[i] = min(after, before);
42+
}
43+
}
44+
45+
long long sol = 0;
46+
47+
if(cnt > n / 2) {
48+
cnt -= (n / 2);
49+
for(int i = 0; cnt > 0 && i < n; ++i) {
50+
if(vis[i] && a[i] != 0) {
51+
++sol;
52+
--cnt;
53+
}
54+
}
55+
56+
for(int i = 0; cnt > 0 && i < n; ++i) {
57+
if(vis[i] && a[i] == 0) {
58+
sol += 2;
59+
--cnt;
60+
}
61+
}
62+
63+
printf("%lld\n", sol);
64+
return 0;
65+
}
66+
67+
sort(mn, mn + n);
68+
69+
for(int i = 0; i < n / 2; ++i)
70+
sol += mn[i];
71+
72+
printf("%lld\n", sol);
73+
74+
return 0;
75+
}
76+

CodeForces/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,7 @@
316316
- [864C. Bus](http://codeforces.com/contest/864/problem/C)
317317
- [890A. ACM ICPC](http://codeforces.com/contest/890/problem/A)
318318
- [890B. Vlad and Cafes](http://codeforces.com/contest/890/problem/B)
319+
- [898A. Rounding](http://codeforces.com/contest/898/problem/A)
320+
- [898B. Proper Nutrition](http://codeforces.com/contest/898/problem/B)
321+
- [898C. Phone Numbers](http://codeforces.com/contest/898/problem/C)
322+
- [898E. Squares and not squares](http://codeforces.com/contest/898/problem/E)

0 commit comments

Comments
 (0)