nyoj 1099 Lan Xiang's Square (水题)
- 题目1099
- 题目信息
- 运行结果
- 本题排行
- 讨论区
Lan Xiang's Square
- 描述
-
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. :)
- 来源
- myself
-
上传者
ACM_张开创题意:给出四个点坐标,判断是否能组成正方形。
证明:四条边相等,并且有一个角是直角 为正方形。
题很简单 ,自己的思路也一直整错 可就是wa
可能数据太给力了,调试n次,发现sqrt()导致精度损失。 这个错误可真难找。。。
先贴上wa的代码
-
#include <stdio.h> #include <math.h> #define inf 500000005 int main() {double a[4],b[4],x1,x2,x3,x4,y1,y2,y3,y4;double sum1,sum2,l1,l2,l3,l4,l;int i,t;scanf("%d",&t);while(t--){sum1=sum2=0,x1=x2=x3=x4=y1=y2=y3=y4=inf;for(i=0;i<4;i++)scanf("%lf %lf",&a[i],&b[i]),sum1+=a[i],sum2+=b[i];sum1=sum1/4,sum2=sum2/4;for(i=0;i<4;i++){if(a[i]<sum1&&b[i]>=sum2)x1=a[i],y1=b[i];if(a[i]<=sum1&&b[i]<sum2)x2=a[i],y2=b[i];if(a[i]>=sum1&&b[i]>sum2)x3=a[i],y3=b[i];if(a[i]>sum1&&b[i]<=sum2)x4=a[i],y4=b[i];}if(x1==inf||x2==inf||x3==inf||x4==inf||y1==inf||y2==inf||y3==inf||y4==inf){printf("No\n");continue;}l1=sqrt(pow(y1-y2,2)+pow(x1-x2,2));l2=sqrt(pow(y2-y4,2)+pow(x2-x4,2));l3=sqrt(pow(y3-y4,2)+pow(x3-x4,2));l4=sqrt(pow(y1-y3,2)+pow(x1-x3,2));l=sqrt(pow(y3-y2,2)+pow(x3-x2,2));if(l1==l2&&l1==l3&&l1==l4&&fabs(l1*l1+l4*l4-l*l)<0.00001)printf("Yes\n");elseprintf("No\n");}return 0; }
ac代码
#include <stdio.h> #include <math.h> #define inf 500000005 int main() {double a[4],b[4],x1,x2,x3,x4,y1,y2,y3,y4;double sum1,sum2,l1,l2,l3,l4,l;//l1,l2,l3,l4,l分别表示四条边和一个对角线。int i,t;scanf("%d",&t);while(t--){sum1=sum2=0,x1=x2=x3=x4=y1=y2=y3=y4=inf;//初始坐标for(i=0;i<4;i++)scanf("%lf %lf",&a[i],&b[i]),sum1+=a[i],sum2+=b[i];sum1=sum1/4,sum2=sum2/4;for(i=0;i<4;i++)//更新坐标{if(a[i]<sum1&&b[i]>=sum2)x1=a[i],y1=b[i];if(a[i]<=sum1&&b[i]<sum2)x2=a[i],y2=b[i];if(a[i]>=sum1&&b[i]>sum2)x3=a[i],y3=b[i];if(a[i]>sum1&&b[i]<=sum2)x4=a[i],y4=b[i];}if(x1==inf||x2==inf||x3==inf||x4==inf||y1==inf||y2==inf||y3==inf||y4==inf)//如果有一个坐标未更新 ,no{printf("No\n");continue;}l1=pow(y1-y2,2)+pow(x1-x2,2);//和wa不同的地方l2=sqrt(pow(y2-y4,2)+pow(x2-x4,2));l3=sqrt(pow(y3-y4,2)+pow(x3-x4,2));l4=pow(y1-y3,2)+pow(x1-x3,2);//同上l=pow(y3-y2,2)+pow(x3-x2,2);//同上if(sqrt(l1)==l2&&sqrt(l1)==l3&&sqrt(l1)==sqrt(l4)&&l1+l4==l)printf("Yes\n");else printf("No\n");}return 0; }
nyoj 1099 Lan Xiang's Square (水题)相关推荐
- nyoj 1099 Lan Xiang's Square(判断正方形问题)
给四个点判断是否能构成正方形. 正方形判定定理: 1:对角线相等的菱形是正方形 2:对角线互相垂直的矩形是正方形,正方形是一种特殊的矩形 3:四边相等,有一个角是直角的四边形是正方形 4:一组邻边相等 ...
- 【nyoj - 890】 分东西 (水题 二进制)
题干: 分东西 时间限制:1000 ms | 内存限制:65535 KB 难度:1 输入 第一行输出一个数i表示有i组情况(0<i<=10) 接下来的i行,每一行输入两个个数M(0&l ...
- NYOJ - [第八届河南省程序设计大赛]Distribution(水题)
题目链接:http://nyoj.top/problem/1241 内存限制:64MB 时间限制:2000ms 题目描述 One day , Wang and Dong in the Dubai de ...
- NYOJ 628--小媛在努力【水题】
小媛在努力 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 在多媒体数据处理中,数据压缩算法尤为重要.小媛上完课后就想自己发明一个数据压缩算法.她想呀想,终于想到一个方法 ...
- 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)
题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题
A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...
- 水题/poj 1852 Ants
1 /* 2 PROBLEM:poj1852 3 AUTHER:Nicole 4 MEMO:水题 5 */ 6 #include<cstdio> 7 using namespace std ...
- HDU2673-shǎ崽(水题)
如果不能够直接秒杀的题,就不算水题.又应证了那句话,有时候,如果在水题上卡住,那么此题对于你来说,也就不算是水题了额~~ 刚睡醒,迷迷糊糊. 题目的意思很简单,求一个最大的,再求一个最小的.几乎是什么 ...
- 图论刷水题记录(二)(最短路-----SPFA算法)
继第一篇的后续,又来刷水题了,写的是SPFA算法,这个算法的复杂度比较玄学,感觉能不用就不用了,但是他的好处就是可以判断负圈. 3月26日: 1.POJ 1847 Tram 题意:在一个交通网络上有N ...
最新文章
- 华为报告称2013年大数据将引发IT系统大变革
- TCP全局同步问题发生的原因
- Python---udp绑定信息以及网络通信过程
- MFC六大核心机制之五、六:消息映射和命令传递
- sharding-jdbc整合mybatis
- python bool值要注意的一些地方
- SQL点滴19—T-SQL中的透视和逆透视
- Spring MVC – Flash属性
- 通过options探测服务器信息,WEB服务器启用了OPTIONS方法
- Eclipse窗口显示:独立、嵌入式
- 自己动手实现分布式任务调度框架
- MPLS_×××入门中文版
- Linux文件目录命令,有这些就够了?
- TYUT-A专题题解(二)
- 图之Dijkstra算法
- kubernetes(k8s)第五部分之K8s部署nginx
- 如何在手机上将图片转换为文字
- krpano plugin interface
- WIN_DOS经典大全
- 学习java随堂练习-20220616
热门文章
- 基于Vue+Element Plus实现快速导航
- PageHelper 分页,total总数等于每页数量的问题解决
- mysql语句大小写要求_mysql踩坑(一)-大小写规则
- MTK虚拟sensor梳理
- c语言一维数组n个元素求和,C++编程一维数组元素求和?
- 20175208 实验二 《Java面向对象程序设计》实验报告
- 【数学建模】经典简单例题实例1
- 20款有趣的英文卡通免费字体
- ArcGIS坡度分析(解决坡度分析80-89°高值居多)
- 汽车厂家系统服务器费用,汽车vps费用