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
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 60;
char c[N];

void run()
{
scanf("%s", c + 1);
int n = strlen(c + 1);
map<char, int>st;
st[c[1]] ++;
for(int i = 2; i <= n / 2; ++ i)
{
if(st.find(c[i]) == st.end())
{
printf("YES\n");
return;
}
}
printf("NO\n");
}

int main()
{
// freopen("1.in", "r", stdin);
int t;cin >> t;
while(t --) run();
return 0;
}

B

直接枚举即可

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
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
int a[N];
LL s[N];

void run()
{
int n, k;
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; ++ i) s[i] = s[i - 1] + a[i];
LL ans = 0;
for(int i = 0; i <= k; ++ i)
{
int l = 2 * (k - i), r = n - i;
ans = max(ans, s[r] - s[l]);
}
printf("%lld\n", ans);
}

int main()
{
// freopen("1.in", "r", stdin);
int t;cin >> t;
while(t --) run();
return 0;
}

C

C比赛时没出,思路上没什么大问题,就是差一点(bushi,说到底还是自己菜)
我们可以发现这道题只需要找一下有多少个波峰和波谷就可以了,因为波峰波谷一定不能删除

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
#include <bits/stdc++.h>

using namespace std;
typedef long long LL;
const int N = 3e5 + 10;

void run()
{
int n;
scanf("%d", &n);
vector<int>a(n);
for(int i = 0; i < n; ++ i) scanf("%d", &a[i]);
n = unique(a.begin(), a.end()) - a.begin();
int ans = 0;
for(int i = 0; i < n; ++ i)
{
if(i == 0 || i == n -1 || a[i] > a[i - 1] == a[i] > a[i + 1]) ans ++;
}
printf("%d\n", ans);
}

int main()
{
// freopen("1.in", "r", stdin);
int t;cin >> t;
while(t --) run();
return 0;
}