IOI 2017 Practice Contest mountains
Mountains
题意:
选最多的点使得两两看不见。
分析:
分治,solve(l,r)为区间[l,r]的答案。那么如果不选最高点,分治两边即可,选了最高点,那么在最高点看不见的区间里分治。
代码:
#include"mountains.h"
#include<bits/stdc++.h>
using namespace std; const int N = ;
int y[N];
int f[N][N]; bool Judge(int a,int b,int c) { // a see c ?
// ((y[a] - y[b]) / (a - b)) > ((y[a] - y[c]) / (a - c));
return 1ll * (y[a] - y[b]) * (a - c) > 1ll * (y[a] - y[c]) * (a - b);
} int solve(int l,int r) {
if (f[l][r]) return f[l][r];
if (l > r) return ;
if (l == r) return ;
int pos = -, mx = -;
for (int i=l; i<=r; ++i) if (y[i] > mx) pos = i, mx = y[i];
int ans1 = solve(l, pos - ) + solve(pos + , r); // select max_height_node int ans2 = ; // don't select this node
for (int i=pos-,j; i>=l; i=j) {
for (j=i-; j>=l; --j) { // i can see pos
if (Judge(j, i, pos)) { // j can't see pos
if (j == l) ans2 += solve(l, i - );
continue;
}
if (j + <= i - ) ans2 += solve(j + , i - ); // this Section can't see pos
break;
}
}
for (int i=pos+,j; i<=r; i=j) {
for (j=i+; j<=r; ++j) {
if (Judge(pos, i, j)) {
if (j == r) ans2 += solve(i + , r);
continue;
}
if (i + <= j - ) ans2 += solve(i + , j - );
break;
}
}
return f[l][r] = max(ans1, ans2 + );
} int maximum_deevs(vector<int> A) {
int n = A.size();
for (int i=; i<=n; ++i) y[i] = A[i - ];
return solve(, n);
}
IOI 2017 Practice Contest mountains的更多相关文章
- ACM ICPC 2017 Warmup Contest 9 I
I. Older Brother Your older brother is an amateur mathematician with lots of experience. However, hi ...
- ACM ICPC 2017 Warmup Contest 9 L
L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...
- Fighting For 2017 Season Contest 1
比赛地址[https://vjudge.net/contest/147011#problem/A].960626 题目一:[http://codeforces.com/problemset/probl ...
- JAG Practice Contest for ACM-ICPC Asia Regional 2016
2016弱校联盟十一专场10.3 传送门 B. Help the Princess! 计算皇后和士兵谁先到达出口即可. C. We don't wanna work! 两个优先队列维护工作中积极性最小 ...
- JAG Practice Contest for ACM-ICPC Asia Regional 2016.K.Non-redundant Drive(点分治)
Atcoder vjudge 这标题好长... \(Description\) 给定一棵\(n\)个点的树.在每个点\(i\)你可以补充\(g_i\)的油量,经过一条边需要花费边长的油量.你可以选择从 ...
- JAG Practice Contest for ACM-ICPC Asia Regional 2016 C题【贪心】
camp给出的题解: 题解:贪心,先算出最小需要的长度.然后从左到右依次确定每一位.复杂度O(n)O(n) 长度为 2n2n 的串可以构造出需要 [0,1+3+...+2n-1][0,1+3+...+ ...
- JAG Practice Contest for ACM-ICPC Asia Regional 2016B题【BFS】
题意: 就是公主要逃跑,士兵要抓公主,问你能不能逃跑哇: 思路: 就是终点搞成起点,然后BFS一下就好了,最后枚举一下出口到公主的距离是不是<所有的到士兵的距离: #include <bi ...
- 非传统题初探——AtCoder Practice Contest #B - インタラクティブ練習 (Interactive Sorting)
原题: Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement This is an interac ...
- ACM ICPC 2017 Warmup Contest 1 D
Daydreaming Stockbroker Gina Reed, the famous stockbroker, is having a slow day at work, and between ...
随机推荐
- Junit4所需jar包
在eclipse中新建一个Junit类,运行时出现java.lang.NoClassdeffounderror:org/apache/commons/logging/LogFactory错误,原来是缺 ...
- IBM MQ介绍
转自:http://hi.baidu.com/lubezhang/blog/item/bd308b3b7ecce3ec14cecb4f.html IBM MQ(IBM Message Queue)是I ...
- Allocate exception for servlet ValidateUsernameServlet 异常
如果eclipse无法对类文件进行编译那么运行时就会发生 Allocate exception for servlet ValidateUsernameServlet 异常,说找不到类.
- (一)安装Linux时的磁盘划分
Linux安装中的磁盘划分 安装Ctentos6.3的版本,它使用的默认文件系统类型是ext4. Linux的安装至少要划分为根分区/和swap分区这个两个分区才能正常安装使用. 一般来说应该分为四个 ...
- BZOJ 3289: Mato的文件管理 【莫队 + 树状数组】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=3289 3289: Mato的文件管理 Time Limit: 40 Sec Memory ...
- mybatis实现最简单的增删改查
1.数据库设计 2.项目结构(针对User不用管Blogger) User.java package com.yunqing.mybatis.bean; public class User { pri ...
- 给requests模块添加请求头列表和代理ip列表
Requests 是使用 Apache2 Licensed 许可证的 基于Python开发的HTTP 库,其在Python内置模块的基础上进行了高度的封装,符合了Python语言的思想,通俗的说去繁存 ...
- iOS视频播放(AVFoundation)
iOS视频播放(AVFoundation) 关于iOS平台的音视频处理,苹果官方提供了OC和swift接口的AVFoundation框架,可以进行各种音频播放和剪辑,底层实现使用了GPU加速,编解码效 ...
- 复习宝典之Redis
查看更多宝典,请点击<金三银四,你的专属面试宝典> 第八章:Redis Redis是一个key-value的nosql数据库.先存到内存中,会根据一定的策略持久化到磁盘,即使断电也不会丢失 ...
- tornado用户指引(二)------------tornado协程实现原理和使用(一)
摘要:Tornado建议使用协程来实现异步调用.协程使用python的yield关键字来继续或者暂停执行,而不用编写大量的callback函数来实现.(在linux基于epoll的异步调用中,我们需要 ...