当前位置:网站首页>2/14 preliminary calculation geometry
2/14 preliminary calculation geometry
2022-06-27 16:30:00 【Zhong Zhongzhong】
Properties of convex polygons : It means that every interior angle of a polygon is less than 180180 Degree polygon
Turning the vector to the right means that the image is recessed
https://www.luogu.com.cn/problem/P3744
Make a point in a convex polygon move the least distance to make it become a concave polygon
#include <bits/stdc++.h>
#define inf 1000000000.0
using namespace std;
struct node
{
double x,y;
node (double x=0,double y=0):x(x),y(y){
}
node operator- (const node &r) const
{
return node{
x-r.x,y-r.y};
}
}e[1005];
int n;
double ans=inf;
double cross(node e1,node e2)
{
return fabs(e1.x*e2.y-e1.y*e2.x);
}
double len(node e1,node e2)
{
return sqrt((e1.x-e2.x)*(e1.x-e2.x)+(e1.y-e2.y)*(e1.y-e2.y));
}
double go(int i)
{
node e1=e[i]-e[i+1],e2=e[i]-e[i+2];
return cross(e1,e2)/len(e2,node(0.0));
}
signed main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%lf%lf",&e[i].x,&e[i].y);
}
e[n+1]=e[1];e[n+2]=e[2];
for(int i=1;i<=n;i++)
ans=min(ans,go(i));
cout<<ans/2<<endl;
return 0;
}
Simple application of cross product
https://www.luogu.com.cn/problem/P1355
Notice the order of the coordinates and the direction of the vector
#include <bits/stdc++.h>
using namespace std;
int read()
{
int ret = 0, ch;
while(!isdigit(ch = getchar()) && ch != '-');
bool bm = (ch == '-'); if(bm) ch = getchar();
while(ret = ret * 10 + (ch - '0'), isdigit(ch = getchar()));
return bm ? -ret : ret;
}
struct node
{
int x,y;
bool operator==(const node &r) const
{
return x == r.x && y == r.y;
}
node operator-(const node &r) const
{
return (node){
x-r.x,y-r.y};
}
}a,b,c,p,q;
int cross(const node &a,const node &b) // Cross product
{
return a.x*b.y-a.y*b.x;
}
bool inn(const node &a,const node &b,const node &c)
{
// Judge on the side
return a.x>=min(b.x,c.x)&&a.x<=max(b.x,c.x)
&& a.y>=min(b.y,c.y)&&a.y<=max(b.y,c.y)
&& cross(a-b,a-c)==0;
}
bool innn(const node &a,const node &b,const node &c,const node &d)
{
// Judge whether it is inside
return (cross(d-c,a-d)^cross(d-c,b-d))>=0;
// If the vector AB× vector BP And vector AB× vector BH Same number , be q,P stay AB Ipsilateral .
}
signed main()
{
a.x=read()*3;a.y=read()*3;
b.x=read()*3;b.y=read()*3;
c.x=read()*3;c.y=read()*3;
p.x=read()*3;p.y=read()*3;
q.x=(a.x+b.x+c.x)/3;
q.y=(a.y+b.y+c.y)/3;
if(p==a||p==b||p==c)
cout<<"4"<<endl;
else if(inn(p,a,b)||inn(p,b,c)||inn(p,c,a))
cout<<"3"<<endl;
else if(innn(p,q,a,b)&&innn(p,q,b,c)&&innn(p,q,c,a))
cout<<"1"<<endl;
else
cout<<"2"<<endl;
return 0;
}
vector a=(x1,y1) and b=(x2,y2) Collinear , available x1y2-x2y1==0
If two points are on same straight line , be x1y2=x2y1
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn=705;
const int inf=0x3f3f3f3f;
struct node
{
int x,y;
}e[maxn];
int n,ma;
signed main()
{
scanf("%lld",&n);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld",&e[i].x,&e[i].y);
}
for(int i=1;i<=n-1;i++)
{
for(int j=i+1;j<=n;j++)
{
int tmp=2;
node p;
p.x=e[j].x-e[i].x;p.y=e[j].y-e[i].y;
for(int g=1;g<=n;g++)
{
if(g==i||g==j)
continue;
node p1;
p1.x=e[g].x-e[i].x;p1.y=e[g].y-e[i].y;
if(p.x*p1.y==p.y*p1.x)
tmp++;
}
ma=max(ma,tmp);
}
}
cout<<ma<<endl;
return 0;
}
边栏推荐
- C语言课程设计
- 3.4 fixed number of cycles II
- The two trump brand products of Langjiu are resonating in Chengdu, continuously driving the consumption wave of bottled liquor
- Etcd可视化工具:Kstone部署(一),基于Helm快速部署
- The array of C language is a parameter to pass a pointer
- 利用Redis实现订单30分钟自动取消
- Slow bear market, bit Store provides stable stacking products to help you cross the bull and bear
- 事务的四大特性
- 实现简单的三D立方体自动旋转
- Smart wind power | Tupu software digital twin wind turbine equipment, 3D visual intelligent operation and maintenance
猜你喜欢

Leetcode daily practice (longest substring without repeated characters)

Etcd visualization tool: kstone deployment (I), rapid deployment based on Helm

List to table

【多线程】线程通信调度、等待集 wait() 、notify()
![[Niuke's questions] nowcoder claims to have remembered all Fibonacci numbers between 1 and 100000. To test him, we gave him a random number N and asked him to say the nth Fibonacci number. If the nth](/img/70/fa79ba38e28c41ed28bce2ec73cd79.png)
[Niuke's questions] nowcoder claims to have remembered all Fibonacci numbers between 1 and 100000. To test him, we gave him a random number N and asked him to say the nth Fibonacci number. If the nth

郎酒两大王牌产品成都联动共振,持续带动光瓶酒消费浪潮

The interview lasted for half a year. Last month, I successfully got Alibaba p7offer. It was all because I chewed the latest interview questions in 2020!

EMQ 助力青岛研博建设智慧水务平台

Hung - Mung! HDD Hangzhou station · salon hors ligne vous invite à construire l'écologie

# Cesium实现卫星在轨绕行
随机推荐
实现简单的三D立方体自动旋转
事务的隔离级别详解
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
Etcd可视化工具:Kstone部署(一),基于Helm快速部署
模拟进程调度
继手机之后 报道称三星也削减了电视等家电产品线的产量
基于 Nebula Graph 构建百亿关系知识图谱实践
Weekly snapshot of substrate technology 20220411
P.A.R.A 方法在思源的简易应用(亲测好用)
# Cesium实现卫星在轨绕行
ORM表关系及操作
Introduce you to ldbc SNB, a powerful tool for database performance and scenario testing
3.3 one of the fixed number of cycles
数组表示若干个区间的集合,请你合并所有重叠的区间,并返回 一个不重叠的区间数组,该数组需恰好覆盖输入中的所有区间 。【LeetCodeHot100】
What is the open source compatibility of the current version of polardb-x? mysql8?
LeetCode每日一练(杨辉三角)
Construction and management practice of ByteDance buried point data flow
树莓派初步使用
The role of the symbol @ in MySQL
面试半年,上个月成功拿到阿里P7offer,全靠我啃烂了这份2020最新面试题!