ABC 串讲 ——328(A~C)

Leo2011 大气压强

A Not Too Hard

也是醉了,循环枚举就得了呗? 遍历一遍数组就可以 AC 了。

ACCode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <bits/stdc++.h>

using namespace std;

const int N = 10;
int n, x, a[N], sum;

int main() {
scanf("%d%d", &n, &x);
for (int i = 1;i <= n;i++) {
scanf("%d", &a[i]);
if (a[i] <= x)
sum += a[i];
}
printf("%d\n", sum);
return 0;
}

AC 记录

B 11/11

我生日哎。

数位最多两位,这个数位分解很简单。这里有一种简单粗暴的办法:如果十位是 0 就让它等于个位就好了,反正不影响结果。

ACCode:

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

using namespace std;

const int N = 110;
int n, d[N], ans;

int main() {
scanf("%d", &n);
for (int i = 1;i <= n;i++) {
scanf("%d", &d[i]);
for (int j = 1;j <= d[i];j++) {
int ge = j % 10, shi = j / 10, gei = i % 10, shii = i /10;
if (shi == 0)
shi = ge;
if (shii == 0)
shii = gei;
if (ge == shi && shi == gei && gei == shii)
ans++;
}
}
printf("%d\n", ans);
return 0;
}

AC 记录

C Consecutive

Tips:区间求答案,就想前缀和。

如果相等,就在答案数组上 + 1,否则就不加

ACCode with 注释:

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

using namespace std;

const int N = 3e5 + 10;
int n, q, l, r, cnt[N];
string s;

int main() {
scanf("%d%d", &n, &q);
cin >> s;
s = ' ' + s; // 前缀和从1开始
for (int i = 1;i <= n;i++)
if (s[i] == s[i + 1]) // 相等
cnt[i] = cnt[i - 1] + 1; // 记录
else
cnt[i] = cnt[i - 1];
for (int i = 1;i <= q;i++) {
scanf("%d%d", &l, &r);
printf("%d\n", cnt[r - 1] - cnt[l - 1]);
/*因为上面是s[i + 1]与s[i]相同就记录了,
所以要用cnt[r - 1]以防在最后一组相同的区间内只有其中一个字符,
即避免如aabb中的bb在筛查1~3的时候被计算*/
}
return 0;
}

什么蹩脚英语。

AC 记录

  • 标题: ABC 串讲 ——328(A~C)
  • 作者: Leo2011
  • 创建于 : 2024-01-19 21:18:04
  • 更新于 : 2024-08-21 22:56:03
  • 链接: https://leo2011.eu.org/2024/01/19/abc-chuan-jiang-328-a-c/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
评论
目录
ABC 串讲 ——328(A~C)