题目链接

BZOJ2924

题解

题面有误。。是\(45°\)

如果两个点间连线与\(x\)轴夹角在\(45°\)以内,那么它们之间连边

求最小路径覆盖 = 最长反链

由于\(45°\)比较难搞,我们利用复数翻转一下,逆时针旋转\(45°\)

这样就求一条从左上到右下的最长链

我们将所有点按\(x\)排序,令\(f[i]\)表示\(i\)结尾的最长链

那么

\[f[i] = max\{f[j] + 1\} \quad [j < i \; y_j > y_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定理 + 树状数组】的更多相关文章

  1. BZOJ2924 : [Poi1998]Flat broken lines

    首先旋转坐标系 $x'=x-y$ $y'=-x-y$ 则对于一个点,它下一步可以往它左上角任意一个点连线. 根据Dilworth定理,答案=这个偏序集最长反链的长度. 设f[i]为到i点为止的最长反链 ...

  2. TOJ 4105 Lines Counting (树状数组)

    题意:给定N条线段,每条线段的两个端点L和R都是整数.然后给出M个询问,每次询问给定两个区间[L1,R1]和[L2,R2],问有多少条线段满足:L1≤L≤R1 , L2≤R≤R2 ? 题解,采用离线做 ...

  3. 【BZOJ】2924: [Poi1998]Flat broken lines

    题意 平面上有\(n\)个点,如果两个点的线段与\(x\)轴的角在\([-45^{\circ}, 45^{\circ}]\),则两个点可以连线.求最少的折线(折线由线段首尾相连)使得覆盖所有点. 分析 ...

  4. 【XSY2727】Remove Dilworth定理 堆 树状数组 DP

    题目描述 一个二维平面上有\(n\)个梯形,满足: 所有梯形的下底边在直线\(y=0\)上. 所有梯形的上底边在直线\(y=1\)上. 没有两个点的坐标相同. 你一次可以选择任意多个梯形,必须满足这些 ...

  5. 【十分不错】【离线+树状数组】【TOJ4105】【Lines Counting】

    On the number axis, there are N lines. The two endpoints L and R of each line are integer. Give you ...

  6. TOJ 4105 Lines Counting(离线树状数组)

    4105.   Lines Counting Time Limit: 2.0 Seconds   Memory Limit: 150000K Total Runs: 152   Accepted Ru ...

  7. UVA - 1471 Defense Lines 树状数组/二分

                                  Defense Lines After the last war devastated your country, you - as the ...

  8. uva 12356 Army Buddies 树状数组解法 树状数组求加和恰为k的最小项号 难度:1

    Nlogonia is fighting a ruthless war against the neighboring country of Cubiconia. The Chief General ...

  9. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

随机推荐

  1. VS Help Viewer 显示内容为HTML源码的问题

    万恶的IE10 为了学习,安装了一套Windows Server 2012+SQL 2012+VS 2012的环境,整体感觉还不错,只是在使用Help Viewer查看帮助的时候,发现显示内容居然为H ...

  2. linux部署MantisBT(二)部署php

    二.部署php 1.下载php安装包 http://php.net/downloads.php 2.安装php yum install libxml2 yum install libxml2-deve ...

  3. Memcached命令-存储命令-查找命令-清理命令

    Memcached set 存储命令 Memcached set 命令用于将 value(数据值) 存储在指定的 key(键) 中. 如果set的key已经存在,该命令可以更新该key所对应的原来的数 ...

  4. nginx web服务器的安装使用

    nginx是一个web服务器(高性能web服务器),类似于apache服务器和iis服务器,由于nginx服务器具有轻量级高并发的特点,目前nginx的使用已经超越了apache. nginx介绍:n ...

  5. KVM存储虚拟化---玩转openstack

    KVM 的存储虚拟化是通过存储池(Storage Pool)和卷(Volume)来管理的. Storage Pool 是宿主机上可以看到的一片存储空间,可以是多种类型,后面会详细讨论.Volume 是 ...

  6. Spring MVC 整合Swagger的一些问题总结

    在做Spring MVC 整合swagger的时候,遇到的两个问题: 第一个问题 在网上找了一些Spring MVC 和Swagger的例子,照着一步步的配置,结果,到最后,项目都起来了,没有任何问题 ...

  7. quartz入门实例

    一 Quarta介绍 1 Quartz是什么 Quartz就是一个纯 Java 实现的作业调度工具,相当于数据库中的 Job.Windows 的计划任务.Unix/Linux 下的 Cron,但 Qu ...

  8. [ML] the notes

    "Machine Learning is not who has the best algorithm that wins. It is who has the most data.&quo ...

  9. Python的top-level脚本为什么在磁盘上没有对应的字节码?

    在Python中,如果你使用python script.py这样的方式运行Python脚本,那么script.py就被称为top-level脚本.对于Python来说,这个脚本的字节码是不会写入到磁盘 ...

  10. Java之Math类使用小结(转发)

    Java的Math类封装了很多与数学有关的属性和方法,大致如下: public class Main { public static void main(String[] args) { // TOD ...