Skip to content

Commit 0c0c871

Browse files
authored
Add files via upload
1 parent d77b17d commit 0c0c871

File tree

18 files changed

+371
-0
lines changed

18 files changed

+371
-0
lines changed

Benghazi Programming Contest/1.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int t, abc[3], d, e;
6+
7+
int main() {
8+
#ifndef ONLINE_JUDGE
9+
freopen("input.in", "r", stdin);
10+
#endif
11+
12+
scanf("%d", &t);
13+
14+
while(t-- != 0) {
15+
for(int i = 0; i < 3; ++i) {
16+
scanf("%d", abc + i);
17+
}
18+
19+
scanf("%d %d", &d, &e);
20+
21+
sort(abc, abc + 3);
22+
23+
bool can = false;
24+
25+
do {
26+
if(abc[0] + abc[1] <= d && abc[2] <= e) {
27+
can = true;
28+
break;
29+
}
30+
} while(next_permutation(abc, abc + 3));
31+
32+
if(can) {
33+
puts("YES");
34+
} else {
35+
puts("NO");
36+
}
37+
}
38+
39+
return 0;
40+
}

Benghazi Programming Contest/1.jpg

114 KB
Loading

Benghazi Programming Contest/10.cpp

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

Benghazi Programming Contest/10.jpg

140 KB
Loading

Benghazi Programming Contest/2.cpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int t, n, m, best;
6+
int dx[] = {1, 2, 1, 2, -1, -2, -1, -2};
7+
int dy[] = {2, 1, -2, -1, 2, 1, -2, -1};
8+
long long masks[64];
9+
10+
void rec(int i, int j, bool isWhite, int knights, long long orResult);
11+
12+
int cellToIndex(int i, int j) {
13+
return m * i + j;
14+
}
15+
16+
bool isValid(double n, long long orResult) {
17+
return bitset<64>(orResult).count() >= n;
18+
}
19+
20+
inline void recNext(int i, int j, bool isWhite, int knights, long long orResult) {
21+
if(j + 2 < m) {
22+
rec(i, j + 2, isWhite, knights, orResult);
23+
} else {
24+
if (isWhite) {
25+
if(i % 2 == 0) {
26+
rec(i + 1, 1, isWhite, knights, orResult);
27+
} else {
28+
rec(i + 1, 0, isWhite, knights, orResult);
29+
}
30+
} else {
31+
if(i % 2 == 0) {
32+
rec(i + 1, 0, isWhite, knights, orResult);
33+
} else {
34+
rec(i + 1, 1, isWhite, knights, orResult);
35+
}
36+
}
37+
}
38+
}
39+
40+
void rec(int i, int j, bool isWhite, int knights, long long orResult) {
41+
if(isWhite) {
42+
if(isValid(n * m / 2.0, orResult)) {
43+
rec(0, 1, false, knights, orResult);
44+
return;
45+
}
46+
} else {
47+
if(isValid(n * m, orResult)) {
48+
best = min(best, knights);
49+
return;
50+
}
51+
}
52+
53+
if(i >= n || j >= m) {
54+
return;
55+
}
56+
57+
recNext(i, j, isWhite, knights + 1, orResult | masks[cellToIndex(i, j)]);
58+
recNext(i, j, isWhite, knights, orResult);
59+
}
60+
61+
int main() {
62+
#ifndef ONLINE_JUDGE
63+
freopen("input.in", "r", stdin);
64+
#endif
65+
66+
scanf("%d", &t);
67+
68+
while(t-- != 0) {
69+
scanf("%d %d", &n, &m);
70+
71+
for(int i = 0; i < n; ++i) {
72+
for(int j = 0; j < m; ++j) {
73+
int currentCellIndex = cellToIndex(i, j);
74+
masks[currentCellIndex] |= (1LL << currentCellIndex);
75+
76+
for(int k = 0; k < 8; ++k) {
77+
int ni = i + dx[k];
78+
int nj = j + dy[k];
79+
80+
if(ni < 0 || ni >= n || nj < 0 || nj >= m) {
81+
continue;
82+
}
83+
84+
masks[currentCellIndex] |= (1LL << (cellToIndex(ni, nj)));
85+
}
86+
}
87+
}
88+
89+
best = 1e9;
90+
rec(0, 0, true, 0, 0LL);
91+
92+
printf("%d\n", best);
93+
}
94+
95+
return 0;
96+
}

Benghazi Programming Contest/2.jpg

98.1 KB
Loading

Benghazi Programming Contest/4.cpp

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

Benghazi Programming Contest/4.jpg

152 KB
Loading

Benghazi Programming Contest/5.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 t, a, b, x, y;
6+
7+
int main() {
8+
#ifndef ONLINE_JUDGE
9+
freopen("input.in", "r", stdin);
10+
#endif
11+
12+
scanf("%d", &t);
13+
14+
while(t-- != 0) {
15+
scanf("%d %d %d %d", &a, &b, &x, &y);
16+
17+
if(a * b <= x * y) {
18+
puts("YES");
19+
} else {
20+
puts("NO");
21+
}
22+
}
23+
24+
return 0;
25+
}

Benghazi Programming Contest/5.jpg

172 KB
Loading

Benghazi Programming Contest/6.cpp

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

Benghazi Programming Contest/6.jpg

148 KB
Loading

Benghazi Programming Contest/7.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 = 1e5 + 1;
6+
int t, n, p, x, y, a[N];
7+
8+
int main() {
9+
#ifndef ONLINE_JUDGE
10+
freopen("input.in", "r", stdin);
11+
#endif
12+
13+
scanf("%d", &t);
14+
15+
while(t-- != 0) {
16+
scanf("%d %d %d %d", &n, &p, &x, &y);
17+
18+
for(int i = 0; i < n; ++i) {
19+
scanf("%d", a + i);
20+
}
21+
22+
int result = 0;
23+
for(int i = 0; i < p; ++i) {
24+
if(a[i] == 0) {
25+
result += x;
26+
} else {
27+
result += y;
28+
}
29+
}
30+
31+
printf("%d\n", result);
32+
}
33+
34+
return 0;
35+
}

Benghazi Programming Contest/7.jpg

134 KB
Loading

Benghazi Programming Contest/8.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int t, xa, xb, xc;
6+
7+
int main() {
8+
#ifndef ONLINE_JUDGE
9+
freopen("input.in", "r", stdin);
10+
#endif
11+
12+
scanf("%d", &t);
13+
14+
while(t-- != 0) {
15+
scanf("%d %d %d", &xa, &xb, &xc);
16+
17+
if(xa > 50) {
18+
puts("A");
19+
} else if(xb > 50) {
20+
puts("B");
21+
} else if(xc > 50) {
22+
puts("C");
23+
} else {
24+
puts("NOTA");
25+
}
26+
}
27+
28+
return 0;
29+
}

Benghazi Programming Contest/8.jpg

126 KB
Loading

Benghazi Programming Contest/9.cpp

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

Benghazi Programming Contest/9.jpg

136 KB
Loading

0 commit comments

Comments
 (0)