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 ...
随机推荐
- andriod学习一
1.Android软件栈 2.Android模拟器 Android SDK 可以通过ADT+Eclipse或者命令行开发,调试,测试应用程序,设备可以使用模拟器或者真实设备, ...
- PS 去皱纹
1.打开一个有皱纹的图片,选择修复画笔工具,按住Alt键吸取一块光滑的皮肤,然后再在有皱纹的位置上点击即可
- Python里//与/的区别?
1.Python里面//的作用是除法取整,也就是直接取整数部分 例如:5//6=0; 56//3=18 2.而/的作用是直接进行常规的除法运算 例如:56/8=7 程序运算实例如下:
- 词嵌入向量WordEmbedding
词嵌入向量WordEmbedding的原理和生成方法 WordEmbedding 词嵌入向量(WordEmbedding)是NLP里面一个重要的概念,我们可以利用WordEmbedding将一个单 ...
- 面试应该get这三大技能
链接:https://www.nowcoder.com/discuss/84391?type=0&order=3&pos=16&page=0 一.自我介绍凸显学业背景中的隐含信 ...
- Python面向对象-访问限制
在Class内部,可以有字段,方法和属性,而外部代码可以通过直接调用实例变量的方法来操作数据, (1)私有普通字段 比如对于下面的Student类,name字段可以在外面通过对象进行直接访问: cla ...
- Sublime Text 插件推荐——for web developers
楼主向高大上的: web front-end development engineer (好吧,google就是这样翻译的 ^_^)们推荐 ST 插件,在此抛砖引玉: NO.1 :Emmet (原名: ...
- 《剑指offer》---寻找反转数组最小值
本文算法使用python3实现 1.题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转. 输入一个非递减排序的数组的一个旋转,输出旋转数组的最小元素. 例如数组{3,4, ...
- vi/sed等遵循的搜索正则语法
转自:http://blog.csdn.net/lanxinju/article/details/5731843 一.查找 查找命令 /pattern<Enter> :向下查找patter ...
- python redis插件安装
#tar xvzf redis-py-2.2.1.tar.gz #cd redis-py-2.2.1 #python setup.py install 附件: https://app.yinxia ...