NYOJ 1099 Lan Xiang's Square (判断是否为正四边形)
2015-11-27 18:50
253 查看
Lan Xiang's Square
时间限制:1000 ms | 内存限制:65535 KB难度:0
描述
Excavator technology which is strong, fast to Shandong to find Lan Xiang.
Then the question comes.. :)
for this problem , i will give you four points. you just judge if they can form a square.
if they can, print "Yes", else print "No".
Easy ? just AC it.
输入T <= 105 cases.
for every case
four points, and every point is a grid point .-10^8 <= all interger <= 10^8。
grid point is both x and y are interger.输出Yes or No样例输入
1 1 1 -1 1 -1 -1 1 -1
样例输出
Yes
提示
you think this is a easy problem ? you dare submit, i promise you get a WA. :)
水
大意:给出四个点,判断围成的图形是否为正四边形
思路:直接判断是否最短边存在4条,最长边存在两条就行了,可以自己手绘一下
ac代码:
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define MAXN 201000
#define MAX(a,b) a>b?a:b
#define fab(a) ((a)>0?(a):-(a))
#define mem(x) memset(x,0,sizeof(x))
#define INF 0xfffffff
using namespace std;
struct s
{
double x,y;
}a[5];
double dis[MAXN];
double fun(s aa,s bb)
{
return sqrt((aa.x-bb.x)*(aa.x-bb.x)+(aa.y-bb.y)*(aa.y-bb.y));
}
int main()
{
int t,i,j;
scanf("%d",&t);
while(t--)
{
for(i=1;i<=4;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
double M=-1.0,mi=INF*1.0;
int k=0;
for(i=1;i<=4;i++)
{
for(j=i+1;j<=4;j++)
{
dis[k]=fun(a[i],a[j]);
M=max(dis[k],M);
mi=min(dis[k],mi);
k++;
}
}
int b=0,c=0;
for(i=0;i<k;i++)
{
if(dis[i]==M)
b++;
else if(dis[i]==mi)
c++;
}
if(b==2&&c==4)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
相关文章推荐
- android gifj加载
- 使用《UrlHash/锚点》解决移动设备中的单页面应用的物理[返回键]带来的困扰
- 使用google protobuf RPC实现echo service
- 谨以此水题作为我贪心的开始,并没有其他的意思……
- Bootstrap历练实例:向列表组添加链接
- Java_解密ThreadLocal
- iOS中使用ZBar扫描二维码自定义扫描界面
- An Overview of Tomcat 6 Servlet Container: Part 2
- 如何将图片插入PCB板上
- iOS Crash文件的解析(转)
- 基于头部跟踪初代码测试
- An Overview of Tomcat 6 Servlet Container : Part 1
- SICP中sqrt(开方)的实现(附C#实现)
- iptables的技术
- 二叉查找树 循环非递归实现
- 其它技巧和经验列表
- javaSE(10)(Map集合)
- Java加密技术(一)——BASE64与单向加密算法MD5&SHA&MAC
- js实现冒泡排序
- Bugs及解决方案列表