CF1142C U2 单调栈

28 篇文章 0 订阅
10 篇文章 0 订阅

Description


已知两个x坐标不同的点可以确定一个二次项系数为1的二次函数。
现在给出n个点,问n^2个二次函数中有多少个图像不包含任何给出的关键点
n ≤ 1 0 5 n\le10^5 n105

Solution


y=x2+bx+c,我们移项得到y-x2=bx+c,令y=y-x^2,那么就变成若干条直线求一个凸壳
当然直接做也可以,原理和上面是一样的

Code


#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define fi first
#define se second

typedef std:: pair <int,int> pair;
typedef double db;
const db eps=1e-8;
const int N=200005;

std:: map <int,int> map;

struct pos {double x,y;} p[N],r[N],stk[N];

int top;

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

pos get(pos a,pos b) {
	double B=(b.y-a.y+a.x*a.x-b.x*b.x)/(b.x-a.x);
	double C=(b.y-B*b.x-b.x*b.x);
	return (pos) {B,C};
}

bool in(pos a,pos b) {
	return (a.x*a.x+a.x*b.x+b.y-a.y>=-eps);
}

int main(void) {
	int n; scanf("%d",&n);
	rep(i,1,n) {
		int x=read(),y=read();
		p[i]=(pos) {(db)x,(db)y};
		if (map.find(x)==map.end()) map[x]=y;
		else {
			if (y>map[x]) map[x]=y;
		}
	}
	for (pair x:map) {
		pos now=(pos) {(db)x.fi,(db)x.se};
		pos tmp=get(stk[top-1],now);
		while (top>1&&in(stk[top],get(stk[top-1],now))) top--;
		stk[++top]=now;
	}
	printf("%d\n", top-1);
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值