hdu5365 Run


Link:http://acm.hdu.edu.cn/showproblem.php?pid=5365


Run

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 529    Accepted Submission(s): 231


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
 


编程思想由于输入数据x、y坐标是整数,对应的点连起来不可能是正三角形、正五边形和正六边形,只可能是正四边形。根据正四边形的判定定理:四条边相等且有一个角是直角的四边形是正四边形。通过枚举每四个点所构成的六条边,若这四个点能构成正四边形,则其所构成的六条边中有四条是正四边形的边,另外两条是正四边形的对角线,且对角线比边长,故通过从小到大排序即可判断前4条边为正四边形的边,后两条为对角线。根据正四边形的边相等和正四边形的对角线与正四边形的边构成直角三角形的勾股关系,即可判定是否为正四边形。

AC code:

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define LL long long 
#define exp 1e-10
#define MAXN 1000010
using namespace std;
const int INF=0x3f3f3f3f;
const int N = 100005;
const int mod = 1000000007;
int n,i,j,k,l,ans;
int x[33],y[33]; 
int e[33];
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
    	for(i=1;i<=n;i++)
    	{
    		scanf("%d%d",&x[i],&y[i]);
		}
		ans=0;
		for(i=1;i<=n;i++)
		{
			for(j=i+1;j<=n;j++)
			{
				for(k=j+1;k<=n;k++)
				{
					for(l=k+1;l<=n;l++)
					{
						e[1]=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
						e[2]=(x[i]-x[k])*(x[i]-x[k])+(y[i]-y[k])*(y[i]-y[k]);
						e[3]=(x[i]-x[l])*(x[i]-x[l])+(y[i]-y[l])*(y[i]-y[l]);
						e[4]=(x[j]-x[k])*(x[j]-x[k])+(y[j]-y[k])*(y[j]-y[k]);
						e[5]=(x[j]-x[l])*(x[j]-x[l])+(y[j]-y[l])*(y[j]-y[l]);
						e[6]=(x[k]-x[l])*(x[k]-x[l])+(y[k]-y[l])*(y[k]-y[l]);
						sort(e+1,e+7);
						if(e[1]==e[2]&&e[2]==e[3]&&e[3]==e[4]&&e[3]+e[4]==e[5])
						{
							ans++;
						}
					}
				}
			}
		}
		printf("%d\n",ans);
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

林下的码路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值