题目链接

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. explain获得使用的key的数据

    bool Explain_join::explain_key_and_len() { if (tab->ref.key_parts) return explain_key_and_len_ind ...

  2. C 计算时间差

    #include <stdio.h>int main(){ //新建四个变量 la 代表小时 kc代表时间 int l,k,a,c; //输入 两个时间 scanf("%d %d ...

  3. django 与 flask里面从已有数据库表中反向生成models

    django: 配置好数据库连接 python manage.py  inspectdb  > models.py 即可反向生成orm使用的models, 注意: > 后面可以定义为指定路 ...

  4. 原生js常用方法

    原生JavaScript设置cookie值 function setCookie(name, value, Hours) { var d = new Date(); var offset = 8; v ...

  5. 对Java对象的认识与理解

    今天是我学习编程以来第一次写博客,记下平日学习所得,本来这几日都在学习web框架 但觉得梳理一下之前所学很有必要.毕竟之前学习Java感觉很粗略只是以考试为目的.所以就以<Thinking in ...

  6. 饥饿的小易(枚举+广度优先遍历(BFS))

    题目描述 小易总是感觉饥饿,所以作为章鱼的小易经常出去寻找贝壳吃.最开始小易在一个初始位置x_0.对于小易所处的当前位置x,他只能通过神秘的力量移动到 4 * x + 3或者8 * x + 7.因为使 ...

  7. c++容器 STL

    2019-01-24 22:30:32 记录学习PAT的一些知识,有待更新 注:本文是对Algorithm 算法笔记 的总结 C++标准库模板(Standard Template Library,ST ...

  8. Python3 小工具-TCP半连接扫描

    from scapy.all import * import optparse import threading def scan(ip,port): pkt=IP(dst=ip)/TCP(dport ...

  9. mac上golang编译出现clang错误

    错误现象 几周前,突然发现我的go 项目编译开始报一种以前从来没有出现过的错误: # runtime/cgo clang: warning: argument unused during compil ...

  10. /etc/fstab 文件如何填写(转)

    转载自 http://hi.baidu.com/jingzhongchen/blog/item/8e6f552dcead7ce98b139952.html 看你对/etc/fstab文件了解多少?   ...