loj 10001 种树


*********贪心,把需要的路段终止点排序,然后在每个区间内判断是否已经满足条件,不满足的从区间右端向左端种树。
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
int i,j,n,h,vis[] = {},ans = ,tot;
struct node
{
int b;
int e;
int t;
}a[];
int cmp(node a,node b)
{
return a.e < b.e;
}
int main()
{
scanf("%d",&n);
scanf("%d",&h);
for(i = ;i <= h;i++)
{
scanf("%d %d %d",&a[i].b,&a[i].e,&a[i].t);
}
sort(a + ,a + + h,cmp);
for(i = ;i <= h;i++)
{
tot = ;
for(j = a[i].b;j <= a[i].e;j++)
{
if(vis[j] == )
{
tot++;
}
if(tot == a[i].t)
break;
}
if(tot < a[i].t)
{
for(j = a[i].e;j >= a[i].b;j--)
{
if(vis[j] == )
{
vis[j] = ;
tot++;
ans++;
}
if(tot == a[i].t)
break;
}
}
}
printf("%d",ans);
return ;
}
loj 10001 种树的更多相关文章
- loj #10001. 「一本通 1.1 例 2」种树
题面 解题思路 贪心,首先按右端点排序,然后从小往大扫,因为要求树最少,所以要尽量放在右端点.然后开个bool数组判断是否种过树即可. 代码 #include<iostream> #inc ...
- loj题目总览
--DavidJing提供技术支持 现将今年7月份之前必须刷完的题目列举 完成度[23/34] [178/250] 第 1 章 贪心算法 √ [11/11] #10000 「一本通 1.1 例 1」活 ...
- Loj 10115 「一本通 4.1 例 3」校门外的树 (树状数组)
题目链接:https://loj.ac/problem/10115 题目描述 原题来自:Vijos P1448 校门外有很多树,学校决定在某个时刻在某一段种上一种树,保证任一时刻不会出现两段相同种类的 ...
- LOJ 一本通一句话题解系列:
第一部分 基础算法 第 1 章 贪心算法 1):「一本通 1.1 例 1」活动安排:按照结束时间排序,然后扫一遍就可以了. 2):「一本通 1.1 例 2」种树:首先要尽量的往区间重叠的部分种树,先按 ...
- LOJ#10106. 「一本通 3.7 例 2」单词游戏
题目链接:https://loj.ac/problem/10106 题目描述 来自 ICPC CERC 1999/2000,有改动. 有 NNN 个盘子,每个盘子上写着一个仅由小写字母组成的英文单词. ...
- LOJ 3184: 「CEOI2018」斐波那契表示法
题目传送门:LOJ #3184. 题意简述: 题目说得很清楚了. 题解: 首先需要了解「斐波那契数系」为何物. 按照题目中定义的斐波那契数列 \(F_n\),可以证明,每个非负整数 \(n\) 都能够 ...
- [Data Structure] 数据结构中各种树
数据结构中有很多树的结构,其中包括二叉树.二叉搜索树.2-3树.红黑树等等.本文中对数据结构中常见的几种树的概念和用途进行了汇总,不求严格精准,但求简单易懂. 1. 二叉树 二叉树是数据结构中一种重要 ...
- projecteuler 10001st prime (求出第10001个质数)
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. ...
- insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a=10001
insert into hi_user_score set hello_id=74372073,a=10001 on duplicate key update hello_id=74372073, a ...
随机推荐
- linux df
显示磁盘使用情况 [hadoopuser@CNSZ443239 ~]$ df 文件系统 1K-块 已用 可用 已 ...
- PHP运算符优先级
if (!$a = $b) { // todo } if (!($a = $b)) { // todo } if ($a = !$b) { // todo } if ($a = (!$b)) { // ...
- Spring重要注解@ControllerAdvice
@ControllerAdvice是一个@Component,用于定义@ExceptionHandler,@InitBinder和@ModelAttribute方法,适用于所有使用@RequestMa ...
- [转][c++][跨平台]c++跨平台开发小结
转自:https://blog.csdn.net/dj0379/article/details/53577135 linux编程与windows编程的差异之处: 1. 文件与目录的大小写以及路径分隔符 ...
- Java String常用的两个方法
- 学习笔记5—Python 将多维数据转为一维数组 (总结)
<code class="language-python">import operator from functools import reduce a = [[1,2 ...
- mui 访问系统相册将图片显示到网页
访问系统相返回值为一个对象,通过转换为字符串可以查看,path.files[0]为返回路径去除路径赋值到src 调用摄像头返回的相片的path为一个路径通过 plus.io.resolveLocalF ...
- Python 闭包(Closure)
Python 闭包 (Closure) 这里介绍一下python 的闭包 基本概念 闭包(closure)是函数式编程的重要的语法结构. 函数式编程的一个特点就是,允许把函数本身作为参数传入另一个函 ...
- centos php5.4 升级 php7
接上篇,edusoho需要php5.5以上版本,于是需要升级本地php php是通过yum默认安装的.以下安装参考 link https://blog.csdn.net/u012569217/arti ...
- 在远程连接一个 Wndows 10的情况下,重启远程机器
如果你从菜单找的话,是找不到这个菜单的!!! 你应该直接按 alt + F4 , 就会出现这个选项了. 参考: https://tommynation.com/shut-windows-10-remo ...