Gym 101606L - Lounge Lizards - [计算几何+LIS]
题目链接:https://codeforces.com/gym/101606/problem/L
题解:
在同一条线上的所有蜥蜴,他们的斜率都是相通的,换句话说可以直接通过斜率将蜥蜴分组。
每一组即代表一条直线上的所有蜥蜴,再将这条直线以TV点为分界分成两条射线,这样每条射线上的蜥蜴,按距离TV从近到远,它们的身高排成一个整数序列,对这个序列求最长上升子序列即可。
需要注意的:
DP求LIS的话是 $O(n^2)$ 的时间复杂度,是过不了的应该,要用贪心+二分 $O(n \log n)$ 求LIS长度;
不确定直接用double类型存斜率是不是会有精度问题,可以用pair<int,int>类型当做分数类来表示斜率,注意约分就好了,还可以省去考虑直线平行坐标轴的问题。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+; int n,X,Y; int tot;
map<pii,int> mp; struct Li
{
ll dist;
int h;
bool operator<(const Li& o)const
{
return dist<o.dist;
}
};
vector<Li> H[][maxn]; inline pii grad(int x,int y)
{
int dx=x-X, dy=y-Y;
int g=__gcd(dx,dy);
return make_pair(dx/g,dy/g);
}
inline ll dist(ll x,ll y)
{
return (x-X)*(x-X)+(y-Y)*(y-Y);
}
inline bool check(int x,int y)
{
if(x==X) return y>Y;
else return x>X;
} int S[maxn],top;
int solve(const vector<Li>& a)
{
S[top=]=a[].h;
for(int i=;i<a.size();i++)
{
int pos=lower_bound(S,S+top+,a[i].h)-S;
S[pos]=a[i].h;
top=max(top,pos);
}
return top+;
} int main()
{
cin>>X>>Y;
cin>>n; mp.clear(), tot=;
for(int i=,x,y,h;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&h);
pii g=grad(x,y);
if(mp[g]==) mp[g]=++tot;
H[check(x,y)][mp[g]].push_back((Li){dist(x,y),h});
} int ans=;
for(int i=;i<=tot;i++)
{
sort(H[][i].begin(),H[][i].end());
sort(H[][i].begin(),H[][i].end());
if(H[][i].size()) ans+=solve(H[][i]);
if(H[][i].size()) ans+=solve(H[][i]);
}
cout<<ans<<endl;
}
Gym 101606L - Lounge Lizards - [计算几何+LIS]的更多相关文章
- 【Codeforces】Gym 101156E Longest Increasing Subsequences LIS+树状数组
题意 给定$n$个数,求最长上升子序列的方案数 根据数据范围要求是$O(n\log n)$ 朴素的dp方程式$f_i=max(f_j+1),a_i>a_j$,所以记方案数为$v_i$,则$v_i ...
- Gym 101917 E 简单计算几何,I 最大流
题目链接 https://codeforces.com/gym/101917 E 题意:给定一个多边形(n个点),然后逆时针旋转A度,然后对多边形进行规约,每个点的x规约到[0,w]范围内,y规约到[ ...
- Gym - 100625G Getting Through 计算几何+并查集
http://codeforces.com/gym/100625/attachments/download/3213/2013-benelux-algorithm-programming-contes ...
- Codeforces Gym 100338B Geometry Problem 计算几何
Problem B. Geometry ProblemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...
- Gym 101606 - A/B/C/D/E/F/G/H/I/J/K/L - (Undone)
链接:https://codeforces.com/gym/101606 A - Alien Sunset 暴力枚举小时即可. #include<bits/stdc++.h> using ...
- 2017 United Kingdom and Ireland Programming(Gym - 101606)
题目很水.睡过了迟到了一个小时,到达战场一看,俩队友AC五个了.. 就只贴我补的几个吧. B - Breaking Biscuits Gym - 101606B 旋转卡壳模板题.然后敲错了. 代码是另 ...
- 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)
A. Alien Sunset 暴力枚举答案即可. #include<cstdio> int n,i,mx; struct P{ int h,r,t; bool night(int x){ ...
- [寒假集训第一场]gym101606 2017 United Kingdom and Ireland Programming Contest (UKIEPC 2017)
3星场 难度在于英文题面太难读懂了QAQ 看样例猜题意的我 博客园的c++主题真丑 A Alien Sunset \(description\) 有\(n\)个星球,每个星球自转时间不一样,所以一天的 ...
- HZNU Training 4 for Zhejiang Provincial Collegiate Programming Contest 2019
今日这场比赛我们准备的题比较全面,二分+数论+最短路+计算几何+dp+思维+签到题等.有较难的防AK题,也有简单的签到题.为大家准备了一份题解和AC代码. A - Meeting with Alien ...
随机推荐
- EmbeddedSolrServer的使用与solor6.3.0的使用
1. 到solr官网下载对应版本的solr: https://lucene.apache.org/solr/ 我下载的是:6.3.0版本(需要JDK8),solr默认集成了jetty容器,而且在 ...
- Pycharm新建模板默认添加作者时间等信息
在pycharm使用过程中,对于每次新建文件的shebang行和关于代码编写者的一些个人信息快捷填写,使用模板的方式比较方便. 方法如下: 1.打开pycharm,选择File-Settings 2. ...
- PowerDesigner的Table视图同时显示Code和Name的方法[转发]
PowerDesigner中Table视图同时显示Code和Name,像下图这样的效果: 实现方法:Tools-Display Preference
- Mockito框架入门教程(二)
接上一篇,继续学习其它的.... 8.找出冗余的互动(即未被验证到的) @Test(expected = NoInteractionsWanted.class) public void find_re ...
- redis 资料
redis是什么: Redis is an open source, BSD licensed, advanced key-value store. It is often referred to a ...
- linux磁盘阵列 逻辑卷管理器
Difficult doesn't mean impossible.It simply meansthat you have to work hard.困难并不代表不可能,它仅仅意味着你必须努力奋斗. ...
- Number Sequence(周期是336!!不是48!!)
1005 Number Sequence 时间限制: 1 Sec 内存限制: 60 MB 题目描述 A number sequence is defined as follows: f(1) = 1 ...
- OpenCV-Python教程9-平滑图像
先解释一个单词 blur:使...模糊不清 滤波与模糊 滤波和模糊都属于卷积,不同的滤波方法之间只是卷积核不同(对线性滤波而言) 低通滤波器是模糊,高通滤波器是锐化 低通滤波器允许低频信号通过,在图像 ...
- java集合性能
https://www.cnblogs.com/xyhuangjinfu/p/5429644.html
- 程序员之路:python3+PyQt5+pycharm桌面GUI开发
http://blog.sina.com.cn/s/blog_989218ad0102wz1k.html 先看效果: 图 1 没错,学过C#的同学应该很熟悉这个界面,按钮风格和界面风格很相似,万万没想 ...