0%

2023牛客寒假算法基础集训营1

2023牛客寒假算法基础集训营1

比赛链接https://ac.nowcoder.com/acm/contest/46800

A

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = 1000000007;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

void solve() {
string a;
cin >> a;
int ans = -1;
int A = 0;
int B = 0;
int C = 5;
int D = 5;
for (int i = 0; i < 10; i++) {
if (a[i] == '1') {
if (i % 2) {
B++;
} else {
A++;
}
} else {
if (i % 2) {
D--;
} else {
C--;
}
}
if (A > D || B > C) {
ans = i + 1;
break;
}
}
cout << ans;
cout << '\n';
return;
}

signed main() {
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}

C

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
using namespace std;

// #define int long long

const int P = 1000000007;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

void solve() {
int ans = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
if (a)
ans++;
}
cout << ans << '\n';
return;
}

signed main() {
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}

D

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = 1000000007;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

double cal(int x, int y, int X, int Y, int XX, int YY) {
double cap = abs(min(x, X) - XX) * abs(min(y, Y) - YY);
double yuce = abs(X - XX) * abs(Y - YY);
double GT = x * y;
double cup = GT + yuce - cap;
double ans = cap / cup;
return ans;
}

void solve() {
int x, y, X, Y;
cin >> x >> y >> X >> Y;
double ans = 0;
ans = max(ans, cal(x, y, X, Y, 0, 0));
ans = max(ans, cal(x, y, X, Y, x, 0));
ans = max(ans, cal(x, y, X, Y, 0, y));
ans = max(ans, cal(x, y, X, Y, x, y));
printf("%.9lf\n", ans);
return;
}

signed main() {
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = 1000000007;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

void solve() {
int n;
cin >> n;
int ans = 10;
int m = n * n - 1;
for (int i = 0; i < m; i++) {
string a;
cin >> a;
for (int j = 0; j < 4; j++) {
if (a[j] == '1')
ans++;
if (a[j] == '2')
ans--;
}
}
cout << ans << '\n';
return;
}

signed main() {
int T = 1;
cin >> T;
while (T--)
solve();
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = 1000000007;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

void solve() {
int n, one;
int ans = 0;
cin >> n >> one;
int zero = n - one;
if (n <= 2) {
cout << 0 << '\n';
return;
}
if (n == one) {
cout << one - 2 << '\n';
return;
}
if (zero >= 2) {
int pair = zero / 2;
zero -= pair * 2;
one -= min(one, pair);
}
ans = max(0ll, one - 1);
cout << ans << '\n';
return;
}

signed main() {
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = 1000000007;
const int MAXN = 100005;
const int INF = 0x3f3f3f3f;

void solve() {

cout << 32;
return;
}

signed main() {
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int P = 1000000007;
const int MAXN = 505;
const int INF = 0x3f3f3f3f;

double dp[MAXN][MAXN];

void solve() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
dp[i][i] = 1;
for (int j = 1; j <= m; j++) {
for (int k = 0; k <= j; k++) {
dp[i][j] =
max(dp[i][j], 1.0 * k / j + 1.0 * dp[i - 1][(j - k)]);
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cout << dp[i][j] << ' ';
}
cout << '\n';
}
printf("%.9lf\n", dp[n][m]);
return;
}

signed main() {
int T = 1;
// cin >> T;
while (T--)
solve();
return 0;
}