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 ...
随机推荐
- 如何访问tomcat所在服务器的其他盘符的资源。
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWA ...
- 牛客网多校训练第一场 I - Substring(后缀数组 + 重复处理)
链接: https://www.nowcoder.com/acm/contest/139/I 题意: 给出一个n(1≤n≤5e4)个字符的字符串s(si ∈ {a,b,c}),求最多可以从n*(n+1 ...
- BZOJ5299:[CQOI2018]解锁屏幕(状压DP)
Description 使用过Android手机的同学一定对手势解锁屏幕不陌生.Android的解锁屏幕由3x3个点组成,手指在屏幕上画一条 线将其中一些点连接起来,即可构成一个解锁图案.如下面三个例 ...
- _bstr_t可接受多字节、UNICODE字符串,方便用以字符集转换
使用_bstr_t需要包含的头文件: #include <comutil.h> #include <comdef.h> // test.cpp : 定义控制台应用程序的入口点. ...
- svn安装配置
1. 安装SVN服务器: 检查是否已安装 # rpm -qa subversion 安装SVN服务器 # yum install httpd httpd-devel subversion mod_da ...
- 使用IPDB调试Python代码
(转载自:https://xmfbit.github.io/2017/08/21/debugging-with-ipdb/) IPDB是什么?IPDB(Ipython Debugger),和GDB类似 ...
- PAT——不吉利的日期(java中date和Calendar使用)
题目描述 在国外,每月的 13 号和每周的星期 5 都是不吉利的.特别是当 13 号那天恰好是星期 5时,更不吉利. 现在给你一个年份,请你从小到大依次输出当年所有13 号是星期 5 的月份. 输入描 ...
- 【题解】洛谷P1879 [USACO06NOV] Corn Fields(状压DP)
洛谷P1879:https://www.luogu.org/problemnew/show/P1879 思路 把题目翻译成人话 在n*m的棋盘 每个格子不是0就是1 1表示可以种 0表示不能种 相邻的 ...
- XCode: 如何添加自定义代码片段
转载自:http://rockonmycode.com/tips/xcode-code-snippets#more-185 我们经常会定义一些retain的property,而且大概每次我们都会像这样 ...
- C#实现双向链表
原文:http://www.cnblogs.com/skywang12345/p/3561803.html#a33 没有C#版本的..是不是很方..不过图和说明很好,引用一下 双向链表 双向链表(双链 ...