nyoj 1099 Lan Xiang's Square (水题)

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. :)
来源
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");
		else
			printf("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 (水题)

时间: 2024-10-18 10:57:01

nyoj 1099 Lan Xiang's Square (水题)的相关文章

nyoj 590 相同的和 【水题(暴力)】

相同的和 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 给出一些数a1,a2,a3,a4.....,an,如果一个连续的字串的和等于常数m,那么这个子串就是我们想要的,那么问题很简单,请求出这样字串的个数? 例如:数列为:3,4,1,6,2,5.m 的值为7时,连续字串{3,4},{1,6},{2,5}满足要求. 输入 每种情况,第一行2个数n,m,n表示有多少个数,m是常数 第二行是n个数的值 (所有的数小于1000) 输出 每种情况个数 样例输入 6 7 3

nyoj-1099-Lan Xiang&#39;s Square(几何,水题)

题目链接 1 /* 2 Name:nyoj-1099-Lan Xiang's Square 3 Copyright: 4 Author: 5 Date: 2018/4/26 9:19:19 6 Description: 7 给4个点,判断是否形成正方形 8 double类型的值比较大小,直接判断==0竟然A了,然而小于1e-6竟然WA 9 */ 10 #include <iostream> 11 #include <cstdio> 12 #include <algorithm

nyoj 1208——水题系列——————【dp】

水题系列 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描述     给你一个有向图,每条边都有一定的权值,现在让你从图中的任意一点出发,每次走的边的权值必须必上一次的权值大的情况下,问你最多能走几条边? 输入 首先一个n和m,分别表示点的数目和边的数目接下来m行,每行三个值x,y,val,表示x到y有路,其权值为val.(1<n,m,val<10^5,0<x,y<=n) 输出 输出最多有的边的数目 样例输入 3 3 1 2 1 2 3 1 3 1 1 6

POJ百道水题列表

以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight Moves1101 Gamblers1204 Additive equations 1221 Risk1230 Legendary Pokemon1249 Pushing Boxes 1364 Machine Schedule1368 BOAT1406 Jungle Roads1411 Annive

HDU 4007 Dave (基本算法-水题)

Dave Problem Description Recently, Dave is boring, so he often walks around. He finds that some places are too crowded, for example, the ground. He couldn't help to think of the disasters happening recently. Crowded place is not safe. He knows there

poj 1005:I Think I Need a Houseboat(水题,模拟)

I Think I Need a Houseboat Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 85149   Accepted: 36857 Description Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land,

hdu-5641 King&#39;s Phone (水题)

题目链接: King's Phone Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 418    Accepted Submission(s): 123 Problem Description In a military parade, the King sees lots of new things, including an An

5.1个人赛解题报告(区间dp,按位与或,图论等水题)

这次5.1打了一场个人赛,已经连赛了三周了,有点疲惫感觉,可能自己太水了,每次都有点小紧张. 这次只解出来三道题,然而有一道按位与按位或的水题不知道思路实在是做题太少,还有就是第一题区间DP,也消耗了不少的时间,但是没有成功的写出来,还是不够熟练啊. 下面写报告 A. System Administrator time limit per test 2 seconds memory limit per test 256 megabytes input standard input output

hdu 1312 Red and Black(BFS水题)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 9684    Accepted Submission(s): 6021 Problem Description There is a rectangular room, covered with square tiles. Each tile is colore