P1276 校门外的树(增强版)
题目入口
https://www.luogu.org/problem/P1276
说说我的感想
好了,第二道水题,我也要去睡觉了
第三遍AC,我写的这么好居然不过, 原因竟然是…
memset不会用了(大写的尴尬)
第一遍没写头文件cstring,第二遍sizeof没用对…还有比我更菜的么
结论:
建议复习memset的用法:memset(trees, 1, sizeof(trees));
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
int l, n, live = 0, dead = 0;
scanf("%d %d", &l, &n);
int trees[10010];
memset(trees, 1, sizeof(trees));
for (int i = 0; i < n; i++){
int judge, a, b;
scanf("%d %d %d", &judge, &a, &b);
if (judge == 1){
for (int j = a; j <= b; j++){
if (trees[j] == 0){
trees[j] = 2;
live++;
}
}
}
else {
for (int j = a; j <= b; j++){
if (trees[j] == 2){
dead++;
live--;
}
trees[j] = 0;
}
}
}
printf("%d\n%d", live, dead);
return 0;
}