Skip to content

Commit 261ff5c

Browse files
committed
Solved problems 1003[A, B, C, D]
1 parent 26469db commit 261ff5c

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int n, a[101];
6+
set<int> st;
7+
8+
int main() {
9+
int cnt = 0;
10+
cin >> n;
11+
for(int i = 0; i < n; ++i)
12+
cin >> a[i];
13+
14+
int res = 0;
15+
while(cnt != n) {
16+
st.clear();
17+
for(int i = 0; i < n; ++i)
18+
if(a[i] != -1 && st.count(a[i]) == 0)
19+
st.insert(a[i]), a[i] = -1, ++cnt;
20+
++res;
21+
}
22+
23+
cout << res << endl;
24+
25+
return 0;
26+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main() {
6+
int a, b, x;
7+
cin >> a >> b >> x;
8+
9+
string s;
10+
if(a > b)
11+
s = "0", --a;
12+
else
13+
s = "1", --b;
14+
15+
for(int i = 0; i < x; ++i) {
16+
if(b > 0 && s.back() == '0')
17+
--b, s += '1';
18+
else if(a > 0)
19+
--a, s += '0';
20+
}
21+
22+
for(int i = 0; i < s.length(); ++i) {
23+
cout << s[i];
24+
if(a > 0 && s[i] == '0')
25+
while(a-- != 0)
26+
cout << '0';
27+
if(b > 0 && s[i] == '1')
28+
while(b-- != 0)
29+
cout << '1';
30+
}
31+
cout << endl;
32+
33+
return 0;
34+
}

CodeForces/1003C. Intense Heat.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 5001;
6+
int n, k, a[N], cs[N];
7+
8+
int main() {
9+
cin >> n >> k;
10+
for(int i = 0; i < n; ++i)
11+
cin >> a[i];
12+
13+
for(int i = 1; i <= n; ++i)
14+
cs[i] = cs[i - 1] + a[i - 1];
15+
16+
long double res = 0, mul = 1.0;
17+
for(int i = 1; i <= n; ++i)
18+
for(int j = i; j <= n; ++j) {
19+
if(j - i + 1 < k)
20+
continue;
21+
22+
res = max(res, mul * (cs[j] - cs[i - 1]) / (j - i + 1));
23+
}
24+
25+
cout << fixed << setprecision(15) << res << endl;
26+
27+
return 0;
28+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int const N = 2e5 + 1;
6+
int n, q, a[N], fr[35], fr1[35];
7+
8+
bool check() {
9+
for(int i = 0; i < 35; ++i)
10+
if(fr1[i] != 0)
11+
return false;
12+
return true;
13+
}
14+
15+
int main() {
16+
scanf("%d %d", &n, &q);
17+
for(int i = 0; i < n; ++i) {
18+
scanf("%d", a + i);
19+
bitset<32> bs(a[i]);
20+
for(int i = 0; i < 32; ++i)
21+
if(bs[i] == 1)
22+
++fr[i];
23+
}
24+
25+
while(q-- != 0) {
26+
int tmp;
27+
scanf("%d", &tmp);
28+
bitset<32> bs(tmp);
29+
30+
memset(fr1, 0, sizeof fr1);
31+
for(int i = 0; i < 32; ++i)
32+
fr1[i] = bs[i];
33+
34+
int cnt = 0;
35+
for(int i = 31; i >= 0; --i) {
36+
if(i > 0 && fr1[i] != 0 && fr[i] == 0) {
37+
fr1[i - 1] += fr1[i] * 2;
38+
fr1[i] = 0;
39+
} else if(i > 0 && fr1[i] != 0 && fr[i] < fr1[i]) {
40+
fr1[i - 1] += (fr1[i] - fr[i]) * 2;
41+
cnt += fr[i];
42+
fr1[i] = 0;
43+
} else if(fr1[i] != 0 && fr[i] >= fr1[i]) {
44+
cnt += fr1[i];
45+
fr1[i] = 0;
46+
}
47+
}
48+
49+
if(check())
50+
printf("%d\n", cnt);
51+
else
52+
puts("-1");
53+
}
54+
55+
return 0;
56+
}

CodeForces/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,3 +469,7 @@
469469
- [988C. Equal Sums](http://codeforces.com/contest/988/problem/C)
470470
- [988D. Points and Powers of Two](http://codeforces.com/contest/988/problem/D)
471471
- [988E. Divisibility by 25](http://codeforces.com/contest/988/problem/E)
472+
- [1003A. Polycarp's Pockets](http://codeforces.com/contest/1003/problem/A)
473+
- [1003B. Binary String Constructing](http://codeforces.com/contest/1003/problem/B)
474+
- [1003C. Intense Heat.cpp](http://codeforces.com/contest/1003/problem/C)
475+
- [1003D. Coins and Queries](http://codeforces.com/contest/1003/problem/D)

0 commit comments

Comments
 (0)