当前位置:网站首页>刷题-洛谷-P1047 校门外的树
刷题-洛谷-P1047 校门外的树
2022-07-25 13:32:00 【宋向上_UP】
P1047 校门外的树-C语言
1、题目

2、解题过程
(1)第一次 没有注意到重复区域问题
结果:
代码:
(2)第二次
结果:
代码:
//洛谷3 P1047 校门外的树
#include <stdio.h>
#define TREE 10001//树的最大数目
int main() {
int l;//马路长度
int m;//区域数 1<=m<=10
int u,v;//区域数值
int tree_num=0;//树的总数
int tree_value[TREE] = {
0 };//对树进行初始化
int sum=0;//路边树的数目
int i;
int j;
scanf("%d %d", &l, &m);//输入马路长度和区域数
tree_num = l + 1;//树的初始数目
for (i = 0; i < tree_num; i++) {
//对树进行标记
tree_value[i] = 1;
}
for (i = 0; i < m; i++) {
scanf("%d %d", &u, &v);
for (j = u; j <= v; j++) {
//对区域内的树进行移除
tree_value[j] = 0;
}
}
for (i = 0; i < tree_num; i++) {
if (tree_value[i] == 1) {
sum++;
}
}
printf("%d", sum);
return 0;
}
边栏推荐
- 若依如何实现用户免密登录配置方法?
- 程序员成长第二十七篇:如何评估需求优先级?
- 外围系统调用SAP的WebAPI接口
- Canvas判断内容为空
- 我的创作纪念日
- Convolutional neural network model -- alexnet network structure and code implementation
- mujoco+spinningup进行强化学习训练快速入门
- 手写jdbc的使用步骤?
- 0720RHCSA
- R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
猜你喜欢

机器学习强基计划0-4:通俗理解奥卡姆剃刀与没有免费午餐定理

0713RHCSA

0715RHCSA

Programmer growth chapter 27: how to evaluate requirements priorities?

arm架构移植alsa-lib和alsa-utils一路畅通

2022年下半年软考初级程序员备考

QGIS loading online map: Gaode, Tiandi map, etc
![[six articles talk about scalablegnn] around www 2022 best paper PASCA](/img/ac/150f6397724593a30aab2805ba5084.png)
[six articles talk about scalablegnn] around www 2022 best paper PASCA

Generate SQL script file by initializing the latest warehousing time of vehicle attributes

Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
随机推荐
Shell common script: get the IP address of the network card
stable_ Baselines quick start
Convolutional neural network model -- alexnet network structure and code implementation
Error: cannot find or load main class XXXX
【AI4Code】CodeX:《Evaluating Large Language Models Trained on Code》(OpenAI)
嵌入式代码如何进行重构?
全网最简单解决方式1045-Access denied for user [email protected](using password:YES)
面试官问我:Mysql的存储引擎你了解多少?
Blocking queue for concurrent programming
Arrays常用方法
安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
VIM tip: always show line numbers
外围系统调用SAP的WebAPI接口
我的创作纪念日
Convolutional neural network model -- googlenet network structure and code implementation
Excel record macro
pycharm不能输入中文解决方法
好友让我看这段代码
Jupyter Notebook介绍
[ai4code final chapter] alphacode: competition level code generation with alphacode (deepmind)