当前位置:网站首页>Brush questions - Luogu -p1047 trees outside the school gate
Brush questions - Luogu -p1047 trees outside the school gate
2022-07-25 13:46:00 【Song Xiangshang_ UP】
P1047 Trees outside the school gate -C Language
1、 subject

2、 The problem solving process
(1) for the first time Did not notice the problem of repeated areas
result :
Code :
(2) The second time
result :
Code :
// Luogu 3 P1047 Trees outside the school gate
#include <stdio.h>
#define TREE 10001// The maximum number of trees
int main() {
int l;// Road length
int m;// Number of areas 1<=m<=10
int u,v;// Area value
int tree_num=0;// The total number of trees
int tree_value[TREE] = {
0 };// Initialize the tree
int sum=0;// Number of roadside trees
int i;
int j;
scanf("%d %d", &l, &m);// Enter the length of the road and the number of areas
tree_num = l + 1;// The initial number of trees
for (i = 0; i < tree_num; i++) {
// Mark the tree
tree_value[i] = 1;
}
for (i = 0; i < m; i++) {
scanf("%d %d", &u, &v);
for (j = u; j <= v; j++) {
// Remove the trees in the area
tree_value[j] = 0;
}
}
for (i = 0; i < tree_num; i++) {
if (tree_value[i] == 1) {
sum++;
}
}
printf("%d", sum);
return 0;
}
边栏推荐
- 【力扣】1030.距离顺序排列矩阵单元格
- G027-op-ins-rhel-04 RedHat openstack creates a customized qcow2 format image
- Applet H5 get mobile number scheme
- Excel record macro
- Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
- leetcode202---快乐数
- Hcip day 9 notes
- @Classmethod decorator
- 剑指offer专项突击版第10天
- Nodejs link MySQL error: Er_ NOT_ SUPPORTED_ AUTH_ MODEError: ER_ NOT_ SUPPORTED_ AUTH_ MODE
猜你喜欢

嵌入式代码如何进行重构?

刷题-洛谷-P1150 Peter的烟

The interviewer asked me: how much do you know about MySQL's storage engine?

ES6数组去重 new Set()

From input URL to web page display

GCD details

刷题-洛谷-P1046 陶陶摘苹果

刷题-洛谷-P1161 开灯

安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1

Uncaught SyntaxError: Octal literals are not allowed in strict mode.
随机推荐
Pycharm cannot input Chinese solution
0719RHCSA
Sports luxury or safety luxury? Which type of Asian Dragon and Volvo S60 should we start with?
Serious [main] org.apache.catalina.util.lifecyclebase Handlesubclassexception initialization component
Explain the precision of floating point numbers in detail
sieve of eratosthenes
Uniapp handles background transfer pictures
安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
Okaleido上线聚变Mining模式,OKA通证当下产出的唯一方式
Concurrent tool set for concurrent programming
【服务器数据恢复】HP EVA服务器存储RAID信息断电丢失的数据恢复
Gym安装、调用以及注册
window unbutu20 LTS apt,wget 安装时 DNS 解析错误
0716RHCSA
0710RHCSA
嵌入式代码如何进行重构?
The migration of arm architecture to alsa lib and alsa utils is smooth
hcip第八天实验
Canvas判断内容为空
0717RHCSA