CF 545C
题意: 砍树, 树会向左或者向右倒,数不能倒重叠, 问最多可以砍多少树
思路: 贪心 + 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的更多相关文章
- Codeforces 划水
Codeforces 566F 题目大意:给定$N$个数,任意两个数之间若存在一个数为另一个数的因数,那么这两个数存在边,求图中最大团. 分析:求一个图最大团为NP-Hard问题,一般不采用硬方法算. ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- 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 ...
- 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 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
随机推荐
- SpringBoot系列: Actuator监控
Sprng Boot 2 actuator变动加大, 网上很多资料都都已经过期. ============================配置项============================ ...
- 15.scrapy模拟登陆案例
1.案例一 a.创建项目 scrapy startproject renren_login 进入项目路径 scrapy genspider renren "renren.com" ...
- 【bzoj 4756】[Usaco2017 Jan] Promotion Counting
Description The cows have once again tried to form a startup company, failing to remember from past ...
- oracle 窗口函数over
select *,sum(字段) over()from table :--相加所有行这个字段的和 select max(字段1),over(partition by 字段2,字段3) from ta ...
- Linux 常用命令(2)
wc命令:用于对文件的行数.单词数和字符数进行统计. wc -w file.txt,显示文件中的单词数,wc -l file.txt,显示文件中的行数,wc -m file.txt,显示文件中的字符数 ...
- Django相关面试题
Django框架的生命请求周期 浏览器上输入地址,回车然后发生了什么? => Http请求生命周期 ? 什么是wsgi 以及作用? 中间件 中间件的执行流程? 中间件的执行流程? 说一下Djan ...
- LinkedQueue的底层实现
package zy813ture; public class MyLinkedQueue1 { private Node head; private Node last = head = new N ...
- 第28月第4天 __bridge_transfer
1. /* NSObject.h Copyright (c) 1994-2018, Apple Inc. All rights reserved. */ #if __has_feature(objc_ ...
- mysql报错:Cause: com.mysql.jdbc.PacketTooBigException
报错信息: Error updating database. Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too ...
- JAVA进阶1
间歇性混吃等死,持续性踌躇满志系列-------------第1天 1.冒泡排序法 import java.util.Arrays; public class SumNum{ public stati ...