BZOJ2924 [Poi1998]Flat broken lines 【Dilworth定理 + 树状数组】
题目链接
题解
题面有误。。是\(45°\)
如果两个点间连线与\(x\)轴夹角在\(45°\)以内,那么它们之间连边
求最小路径覆盖 = 最长反链
由于\(45°\)比较难搞,我们利用复数翻转一下,逆时针旋转\(45°\)
这样就求一条从左上到右下的最长链
我们将所有点按\(x\)排序,令\(f[i]\)表示\(i\)结尾的最长链
那么
\]
离散化一下用树状数组优化
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
#define Redge(u) for (int k = h[u],to; k; k = ed[k].nxt)
#define REP(i,n) for (int i = 1; i <= (n); i++)
#define mp(a,b) make_pair<int,int>(a,b)
#define cls(s) memset(s,0,sizeof(s))
#define cp pair<int,int>
#define LL long long int
#define lbt(x) (x & -x)
using namespace std;
const int maxn = 30005,maxm = 100005,INF = 1000000000;
inline int read(){
int out = 0,flag = 1; char c = getchar();
while (c < 48 || c > 57){if (c == '-') flag = -1; c = getchar();}
while (c >= 48 && c <= 57){out = (out << 3) + (out << 1) + c - 48; c = getchar();}
return out * flag;
}
struct point{
double x,y; int d;
}p[maxn];
inline bool operator <(const point& a,const point& b){
return a.x == b.x ? a.d < b.d : a.x < b.x;
}
int n,tot;
double b[maxn];
inline int getn(double x){return lower_bound(b + 1,b + 1 + tot,x) - b;}
int s[maxn],f[maxn];
void modify(int u,int v){while (u) s[u] = max(s[u],v),u -= lbt(u);}
int query(int u){int re = 0; while (u <= n) re = max(re,s[u]),u += lbt(u); return re;}
int main(){
n = read(); double x,y,s2 = sqrt(2) / 2.0;
REP(i,n){
x = read(); y = read();
p[i] = (point){s2 * (x - y),s2 * (x + y)};
b[i] = p[i].y;
}
sort(b + 1,b + 1 + n); tot = 1;
for (int i = 2; i <= n; i++) if (b[i] != b[tot]) b[++tot] = b[i];
for (int i = 1; i <= n; i++) p[i].d = getn(p[i].y);
sort(p + 1,p + 1 + n); int ans = 0;
for (int i = 1; i <= n; i++){
f[i] = query(p[i].d + 1) + 1;
modify(p[i].d,f[i]);
ans = max(ans,f[i]);
}
printf("%d\n",ans);
return 0;
}
BZOJ2924 [Poi1998]Flat broken lines 【Dilworth定理 + 树状数组】的更多相关文章
- BZOJ2924 : [Poi1998]Flat broken lines
首先旋转坐标系 $x'=x-y$ $y'=-x-y$ 则对于一个点,它下一步可以往它左上角任意一个点连线. 根据Dilworth定理,答案=这个偏序集最长反链的长度. 设f[i]为到i点为止的最长反链 ...
- TOJ 4105 Lines Counting (树状数组)
题意:给定N条线段,每条线段的两个端点L和R都是整数.然后给出M个询问,每次询问给定两个区间[L1,R1]和[L2,R2],问有多少条线段满足:L1≤L≤R1 , L2≤R≤R2 ? 题解,采用离线做 ...
- 【BZOJ】2924: [Poi1998]Flat broken lines
题意 平面上有\(n\)个点,如果两个点的线段与\(x\)轴的角在\([-45^{\circ}, 45^{\circ}]\),则两个点可以连线.求最少的折线(折线由线段首尾相连)使得覆盖所有点. 分析 ...
- 【XSY2727】Remove Dilworth定理 堆 树状数组 DP
题目描述 一个二维平面上有\(n\)个梯形,满足: 所有梯形的下底边在直线\(y=0\)上. 所有梯形的上底边在直线\(y=1\)上. 没有两个点的坐标相同. 你一次可以选择任意多个梯形,必须满足这些 ...
- 【十分不错】【离线+树状数组】【TOJ4105】【Lines Counting】
On the number axis, there are N lines. The two endpoints L and R of each line are integer. Give you ...
- TOJ 4105 Lines Counting(离线树状数组)
4105. Lines Counting Time Limit: 2.0 Seconds Memory Limit: 150000K Total Runs: 152 Accepted Ru ...
- UVA - 1471 Defense Lines 树状数组/二分
Defense Lines After the last war devastated your country, you - as the ...
- uva 12356 Army Buddies 树状数组解法 树状数组求加和恰为k的最小项号 难度:1
Nlogonia is fighting a ruthless war against the neighboring country of Cubiconia. The Chief General ...
- codeforces 597C C. Subsequences(dp+树状数组)
题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...
随机推荐
- libevent学习一
常见的异步IO存在的问题: 1.使用 fcntl(fd, F_SETFL, O_NONBLOCK);,为什么在处理上效率不好. a.在没有数据可读写的时候,循环会不停执行,浪费掉大部分 ...
- H5-基础-day01
类选择器和ID选择器 相同点:可以应用于任何元素不同点: 1.ID选择器只能在文档中使用一次.与类选择器不同,在一个HTML文档中,ID选择器只能使用一次,而且仅一次.而类选择器可以使用多次. 2 ...
- RabbitMQ基础教程之Spring&JavaConfig使用篇
RabbitMQ基础教程之Spring使用篇 相关博文,推荐查看: RabbitMq基础教程之安装与测试 RabbitMq基础教程之基本概念 RabbitMQ基础教程之基本使用篇 RabbitMQ基础 ...
- jmeter多台压力机测试
jmeter控制机会自动将脚本发送至压力机 1.控制机配置 jmeter.properties中配置: remote_hosts=ip1:1099,ip2:1022,ip3:1099 将压力机ip+p ...
- (Python爬虫02) 制定爬虫的学习计划了
公司清退是件很让人郁闷的事情,精,气,神 都会受到影响.焦虑的心态,涣散的眼神, 无所适从的若无其事,人周茶凉的快速交接,各种担忧....平静的面孔波涛汹涌的心.... 认识聊天中满满的套路...还有 ...
- 拥抱移动端,jQueryui触控设备兼容插件
http://touchpunch.furf.com/ ps:要FQ. jQuery UI Touch Punch Touch Event Support for jQuery UI Tested o ...
- Ubuntu14.04下部署FastDFS 5.08+Nginx 1.9.14
最新的版本可以在这里获取,目前下载的最新版本是5.08,更新于2016-02-03.在这里可以找到更多的说明. 下载好后,server端分为两个部分,一个是tracker,一个是storage.顾 ...
- Mybatis generator自动生成mybatis配置和类信息
自动生成代码方式两种: 1.命令形式生成代码,详细讲解每一个配置参数. 2.Eclipse利用插件形式生成代码. 安装插件方式: eclipse插件安装地址:http://mybatis.google ...
- maven 教程二 深入
一:编写POM <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w ...
- 数组的引用——用作形参&返回类型时
一.数组的引用 切入:可以将一个变量定义成数组的引用(这个变量和数组的类型要相同) 形式: int odd[5] = {1, 3, 5, 7, 9}; int (&arr)[5] = odd; ...