7033: Lounge Lizards
时间限制: 10 Sec 内存限制: 128 MB提交: 60 解决: 13
[提交] [状态] [讨论版] [命题人:admin]
题目描述
Monitor lizards are a kind of reptile known mainly for their cold-bloodedness and addiction to computer screens. Due to their love for digital displays, these scaly creatures spend most of their time at home glued to a small television in the lounge.
Conflict has arisen at one particular reptile house. The audience here has grown so large that not everyone will be able to see the screen at once any more; specifically, a lizard will only be able to see enough if it is strictly taller than all of the lizards sitting exactly along the straight line from itself to the television.
Monitor lizards aren’t particularly picky about the actual contents of the screen or being able to see it obliquely (or even from the front)—they just want to be able to keep an eye on it.
The lizards don’t want to move, however. It’s possible to chase a monitor lizard away in order for the ones behind it to see, or leave it alone, but re-homing somewhere else in the room is unthinkable.
Assuming lizards are removed optimally, how many at most can remain and still see the screen?
Conflict has arisen at one particular reptile house. The audience here has grown so large that not everyone will be able to see the screen at once any more; specifically, a lizard will only be able to see enough if it is strictly taller than all of the lizards sitting exactly along the straight line from itself to the television.
Monitor lizards aren’t particularly picky about the actual contents of the screen or being able to see it obliquely (or even from the front)—they just want to be able to keep an eye on it.
The lizards don’t want to move, however. It’s possible to chase a monitor lizard away in order for the ones behind it to see, or leave it alone, but re-homing somewhere else in the room is unthinkable.
Assuming lizards are removed optimally, how many at most can remain and still see the screen?
输入
• one line containing the space-separated integers TX and TY (−106 ≤ TX, TY ≤ 106), the co-ordinates of the television.
• one line containing the integer N (1 ≤ N ≤ 106), the number of lizards.
• N further lines, each containing three space-separated integers XiYiHi (−106 ≤ X, Y ≤106; 1 ≤ H ≤ 106), the co-ordinates and height respectively of one lizard.
The co-ordinates of all televisions and lizards will be distinct.
• one line containing the integer N (1 ≤ N ≤ 106), the number of lizards.
• N further lines, each containing three space-separated integers XiYiHi (−106 ≤ X, Y ≤106; 1 ≤ H ≤ 106), the co-ordinates and height respectively of one lizard.
The co-ordinates of all televisions and lizards will be distinct.
输出
Output the maximum number of lizards that can stay and watch television at once.
样例输入
50 50
2
60 50 1
65 50 2
样例输出
2
来源/分类
将每个点按先 角度递增,后 与中心的距离增加 规则排序,取每个角度上的最长上升子序列求和。
代码如下:
#include <bits/stdc++.h> using namespace std; const int maxn=1e6+10; const int inf=0x3f3f3f3f; const double eps=1e-8; struct node{ int x,y,h; double angle,dis; bool operator<(const node &p) const {return (fabs(angle-p.angle)<eps)?(dis<p.dis):(angle<p.angle);} }a[maxn]; int dp[maxn]; vector<int>v[maxn]; int lis(int i){ int len=v[i].size(); for (int j=0; j<len; j++) dp[j]=inf; for (int j=0; j<len; j++) *lower_bound(dp,dp+len,v[i][j])=v[i][j]; return lower_bound(dp,dp+len,inf)-dp; } int x,y,n; int main(){ scanf("%d%d",&x,&y); scanf("%d",&n); for (int i=1; i<=n; i++){ scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].h); a[i].x-=x,a[i].y-=y; a[i].angle=atan2(a[i].y,a[i].x); a[i].dis=sqrt(1.0*a[i].y*a[i].y+1.0*a[i].x*a[i].x); } sort(a+1,a+1+n); int tot=0; v[++tot].push_back(a[1].h); for (int i=2; i<=n; i++){ if(fabs(a[i].angle-a[i-1].angle)>eps) ++tot; v[tot].push_back(a[i].h); } int ans=0; for (int i=1; i<=tot; i++) ans+=lis(i); printf("%d ",ans); return 0; }