Codeforces Round 429 (Div. 2) 解题报告

A:
题意:找字母出现的最大次数,如果有字母大于$k$,就是NO,否则是YES
解:直接统计

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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
int n, k;
char s[105];
int jh[30];
void clean() {
ms(jh, 0);
}
void solve() {
clean();
scanf("%s", s + 1);
for (int i = 1; i<=n; i++) {
jh[s[i] - 'a']++;
}
for (int i=0;i<26;i++) if (jh[i] > k) {printf("NO\n"); return ;}
printf("YES\n");
}
int main() {
scanf("%d%d", &n, &k), solve();
return 0;
}

B:
题意:玩一个游戏,有一个数组,第一个人先取,第一个人能取走一段奇数和的区间,第二个人能取走一段偶数和的区间,如果到谁取不了就谁输
解:先手能取必赢,数组里有奇数就First赢

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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
int n;
LL a[1000000 + 5], tot = 0;
void clean() {}
void solve() {
clean();
for (int i=1;i<=n;i++) {
scanf("%I64d", &a[i]);
if (a[i] % 2 == 1) {
printf("First\n");
return ;
}
}
printf("Second\n");
}
int main() {
scanf("%d", &n), solve();
return 0;
}

C:
题意:$F_n^k=(n+1)/(k+1)$,给出两个数组$A, B$,你可以把$A$数组进行排列为$A^,$,使得$\sum F^{A^,}_B$最大
解:$F_n^k=(n+1)/(k+1)$要最大,$(n+1)$要尽量大,(k+1)要尽量小,所以两个数组反向排序再对应即可

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
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
struct data {
int v, no;
}a[2*100000+5], b[2*100000+5];
bool cmp1(const data &a ,const data &b) {
return a.v < b.v;
}
bool cmp2(const data &a ,const data &b) {
return a.v > b.v;
}
int m;
int ans[2*100000+5];
void clean() {}
void solve() {
clean();
for (int i=1;i<=m;i++) scanf("%d", &a[i].v), a[i].no = i;
for (int i=1;i<=m;i++) scanf("%d", &b[i].v), b[i].no = i;
sort(a + 1, a +1 +m,cmp2);
sort(b + 1, b +1 +m,cmp1);
for (int i=1;i<=m;i++) ans[b[i].no] = a[i].v;
for (int i=1;i<=m;i++) {
printf("%d", ans[i]);
if (i != m) printf(" "); else printf("\n");
}
}
int main() {
scanf("%d", &m), solve();
return 0;
}

------ 本文结束 ------