2018.10.03 bzoj1610:Line连线游戏(计算几何)

传送门
计算几何入门题,直接算出所有直线的斜率看有多少种不同就行了。
注意处理斜率不存在的情况。
代码:

#include<bits/stdc++.h>
#define N 205
using namespace std;
inline int read(){
	int ans=0,w=1;
	char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return w*ans; 
}
int n,tot=0;
struct Pot{double x,y;}p[N];
bool f=false;
double slope[N*N];
inline int sign(double x){return (x>1e-10)-(x<-1e-10);}
int main(){
	n=read();
	for(int i=1;i<=n;++i)p[i].x=read()*1.0,p[i].y=read()*1,0;
	for(int i=1;i<n;++i)
		for(int j=i+1;j<=n;++j){
			if(!sign(p[i].x-p[j].x)){f=true;continue;}
			slope[++tot]=(p[i].y-p[j].y)/(p[i].x-p[j].x);
		}
	sort(slope+1,slope+tot+1);
	int ans=f+1;
	for(int i=2;i<=tot;++i)if(sign(slope[i]-slope[i-1]))++ans;
	printf("%d",ans);
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值