c语言证明4个点构成正方形,BC之Run

本文介绍了一道编程题目,涉及到在公园椅子间跑出正三角形、正方形、正五边形或正六边形轨迹的问题。通过暴力枚举四个点的方法来判断是否能形成正四边形,并提供了程序实现。虽然地球人知道整点无法构成正三角形、正五边形和正六边形,但文章也提供了相应的几何证明。最后,给出了程序代码以检查所有可能的路径组合。
摘要由CSDN通过智能技术生成

Problem Description

AFA is a girl who like runing.Today,he download an app about runing .The app can record the trace of her runing.AFA will start runing in the park.There are many chairs in the park,and AFA will start his runing in a chair and end in this chair.Between two chairs,she running in a line.she want the the trace can be a regular triangle or a square or a regular pentagon or a regular hexagon.

Please tell her how many ways can her find.

Two ways are same if the set of chair that they contains are same.

Input

There are multiply case.

In each case,there is a integer n(1 < = n < = 20)in a line.

In next n lines,there are two integers xi,yi(0 < = xi,yi < 9) in each line.

Output

Output the number of ways.

Sample Input

4

0 0

0 1

1 0

1 1

Sample Output

1

Source

BestCoder Round #50 (div.2)

Recommend

hujie | We have carefully selected several similar problems for you: 5368 5367 5362 5361 5360

官方题解:

地球人都知道整点是不能构成正五边形和正三边形和正六边形的,所以只需暴力枚举四个点判断是否是正四边形即可。假如你不是地球人,那么即使暴力枚举正三边形和稍微不那么暴力地找正五边形和正六边形也是可以通过的(反正找不到)。

地球人都知道,我当时尽然猪脑子的没怎么注意这点,各种几何,各种优化,之后原来竟然酱紫......

反证法:假设存在坐标平面上的三个整点,组成了正三角形

则将其平移,将其一个顶点与坐标原点重合,则另两个顶点仍然是整点

设一个非原点的顶点M坐标为(a,b) ,另一个顶点为N(c,d), a、b、c、d都是整数

则MO的斜率=

ff906d3294df411f09c27886c8073faf.png,倾斜角=arctan(

ff906d3294df411f09c27886c8073faf.png)

则NO的倾斜角=arctan(

ff906d3294df411f09c27886c8073faf.png)+

e4f0b56c5c24bcc4265684576524c5a1.png

NO的斜率=

006ba5caee67b7d6f6bbde4b1a578892.png

02ff81b3f667cff02f8ca5f24a0329c4.png

因为a、b不全等于0,所以c和d至少有一个是无理数

这和c、d都是整数矛盾

所以坐标平面上的三个整点,一定不能组成正三角形

至于正五边形和正六边形,就交给你们自己去证明了。

判断正方形:

用一个数组用于保存四个点之间的距离,求出两两点之间的距离,若数组不存在所求的距离数值,则添加进数组,若数组超过三个数值,则返回FALSE,否则返回true(其实只要两个就行了,不用距离平方比为1/2,自己举例证明...)

也可以直接算出6个点之间的距离,排下序,前四个相同后两个相同就是正方形....

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

#define INF 0x3f3f3f3f

#define LL long long

#define rd(a) scanf("%d",&a)

#define rdLL(a) scanf("%I64d",&a)

#define rdd(a,b) scanf("%d%d",&a,&b)

#define max(a,b) ((a)>(b)?(a):(b))

#define min(a,b) ((a)

#define MOD 1000000007

#define mem0(a) memset(a,0,sizeof(a))

#define mem1(a) memset(a,1,sizeof(a))

typedef pair P;

int x[25],y[25];

double getdis(int x1,int y1,int x2,int y2){

return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);

}

int judge(int temp[]){///判断是不是正方形

int dis[3], coun=0;

for(int xx=0;xx<4;xx++)

for(int yy=xx+1;yy<4;yy++){

int distmp = getdis(x[ temp[xx] ],y[ temp[xx] ],x[ temp[yy] ],y[ temp[yy] ]);

if(coun==0) dis[coun++]= distmp;

else if(coun==1)

{

if(distmp!=dis[0])

dis[coun++] = distmp;

}

else if(distmp != dis[0] && distmp != dis[1]) return false;

}

return true;

}

int main()

{

int n;

while(~rd(n)){

for(int i=0;i

rdd(x[i],y[i]);

int coun = 0;

for(int i=0;i

for(int j=i+1;j

for(int k = j+1;k

for(int l = k+1 ; l

int temp[4]={i,j,k,l};

if(judge(temp)) coun++;

}

printf("%d\n",coun);

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值