题意: 砍树, 树会向左或者向右倒,数不能倒重叠, 问最多可以砍多少树

思路: 贪心 + Dp吧, 树要尽可能网左倒,这样对后面的树影响较小, 才是最优状态

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = 1e5 + ;
struct Tree
{
int pos, val;
int MaxPos;
}T[maxn];
int Dp[maxn]; int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin >> n;
memset(Dp,,sizeof(Dp));
for(int i = ; i <= n; ++i)
{
cin >> T[i].pos >> T[i].val;
T[i].MaxPos = T[i].pos;
}
Dp[] =;
if(n == ) cout << <<endl;
else if(n == ) cout << << endl;
else
{
for(int i = ; i < n; ++i)
{
int P = T[i].pos, H = T[i].val;
int pre = T[i-].MaxPos;
int l = Dp[i-] , r = Dp[i-];
if(P + H < T[i+].pos) r++ , T[i].MaxPos = P+H;
if(P - H > pre) l++ , T[i].MaxPos = P;
Dp[i] = max(Dp[i-], max(l, r) );
}
Dp[n] = Dp[n-] + ;
cout << Dp[n] << endl;
}
}

CF 545C的更多相关文章

  1. Codeforces 划水

    Codeforces 566F 题目大意:给定$N$个数,任意两个数之间若存在一个数为另一个数的因数,那么这两个数存在边,求图中最大团. 分析:求一个图最大团为NP-Hard问题,一般不采用硬方法算. ...

  2. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  5. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  6. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  7. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

随机推荐

  1. invalid location of tag 解决办法

    转自:https://blog.csdn.net/tanzuai/article/details/41896579 在jsp页面使用标签过程中有时候不注意规则的话,eclipse会提示一些错误,下面针 ...

  2. MySQL 字符集问题

    MySQL 支持许多字符集及其编码方案, 甚至是不同编码之间的转换. 在使用 MySQL 进行应用程序编程时, 常常会出现乱码现象, 这通常是由于客户端没有声明与 MySQL 服务器通信的字符串编码造 ...

  3. 二.LinkedList原理及实现学习总结

    一.LinkedList实现原理概述 LinkedList 和 ArrayList 一样,都实现了 List 接口,但其内部的数据结构有本质的不同.LinkedList 是基于链表实现的(通过名字也能 ...

  4. ext Table中CommandColumn用法

    <ext:CommandColumn Width="250" Header="功能菜单" ColumnID="test"  Butto ...

  5. 28. SpringBoot 集成Redis

    1.引入依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...

  6. thc_业务积累

    查询医生SQL: select aa.id staffid,bb.property_value staffname from thc_warehouse.staff_record aa inner j ...

  7. Docker 容器状态查看 - 五

    1.top stats 查看 docker 容器的状态信息 查看容器状态: docker stats nginx1 查看进程信息: docker top nginx1 2.inspect 使用 doc ...

  8. 基于【磁盘】操作的IO接口:File

    基本操作Api import org.apache.commons.lang3.time.DateFormatUtils; import java.io.*; import java.util.Dat ...

  9. McQueenRPC源码阅读

    1.server 2.client 3.消息格式

  10. Path for IClasspathEntry must be absolute:

    关掉eclipse, 删除workspace工作目录下面的.metadata文件,看不到.metadata文件就 "ctril + H" 就可以看到了.然后重新打开eclipse, ...