Rectangle and Square(判断正方形、矩形)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D
改了N多次之后终于A了,一直在改判断正方形和矩形那,判断正方形时算出六条边再排序,若前四条边相等并且与后两条边满足勾股定理,说明是正方形,
判断矩形时,我先对结构体二级排序,这样四个点有确定的顺序,再用点积判断是否有三个角是直角,是的话就是矩形。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std; struct node
{
int x,y;
}point[]; int cmp(const struct node a,const struct node b)
{
if(a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
int dot(const struct node a, const struct node b,const struct node c, const struct node d)
{
int ans = (a.x-b.x)*(c.x-d.x) + (a.y-b.y)*(c.y-d.y);
if(ans == ) return ;
return ;
} int dis(const struct node a, const struct node b)
{
return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y);
} int main()
{
while(~scanf("%d %d",&point[].x,&point[].y))
{
bool vis[] = {false};
for(int i = ; i <= ; i++)
scanf("%d %d",&point[i].x,&point[i].y);
int flag = ;
int cnt;
struct node t_point[];
for(int i = ; i <= ; i++)
{
for(int j = i+; j <= ; j++)
{
for(int k = j+; k <= ; k++)
{
for(int l = k+; l <= ; l++)
{
int distance[];
distance[] = dis(point[i],point[j]);
distance[] = dis(point[i],point[k]);
distance[] = dis(point[i],point[l]);
distance[] = dis(point[j],point[k]);
distance[] = dis(point[j],point[l]);
distance[] = dis(point[k],point[l]);
sort(distance,distance+);
if( distance[] == distance[] &&
distance[] == distance[] &&
distance[] == distance[] &&
distance[] == distance[] &&
(distance[] + distance[] == distance[]))
{
flag = ;
vis[i] = true;
vis[j] = true;
vis[k] = true;
vis[l] = true;
break;
}
}
if(flag) break;
}
if(flag) break;
}
if(flag) break;
}
if(!flag)
printf("NO\n"); else
{
int tmp1[],tmp2[],t1 = ,t2 = ;
cnt = ;
for(int i = ; i <= ; i++)
{
if(!vis[i])
{
t_point[cnt++] = point[i];
tmp2[t2++] = i;
}
else tmp1[t1++] = i;
}
sort(t_point,t_point+cnt,cmp); if(dot(t_point[],t_point[],t_point[],t_point[]) &&
dot(t_point[],t_point[],t_point[],t_point[]) &&
dot(t_point[],t_point[],t_point[],t_point[]))
{
printf("YES\n");
for(int i = ; i < t1-; i++)
printf("%d ",tmp1[i]);
printf("%d\n",tmp1[t1-]);
for(int i = ; i < t2-; i++)
printf("%d ",tmp2[i]);
printf("%d\n",tmp2[t2-]);
}
else printf("NO\n"); } }
return ;
}
Rectangle and Square(判断正方形、矩形)的更多相关文章
- Codeforces Beta Round #97 (Div. 1) B. Rectangle and Square 暴力
B. Rectangle and Square 题目连接: http://codeforces.com/contest/135/problem/B Description Little Petya v ...
- bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*
bzoj1661[Usaco2006 Nov]Big Square 巨大正方形 题意: n*n的图中有一些J点,一些B点和一些空白点,问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积.n≤ ...
- CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)
题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...
- [LeetCode] Valid Square 验证正方形
Given the coordinates of four points in 2D space, return whether the four points could construct a s ...
- [LeetCode] Maximal Square 最大正方形
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- matlab-霍夫变换详解(判断正方形长方形)
霍夫变换 霍夫变换是1972年提出来的,最开始就是用来在图像中过检测直线,后来扩展能检测圆.曲线等. 直线的霍夫变换就是 把xy空间的直线 换成成 另一空间的点.就是直线和点的互换. 我们在初中数学中 ...
- 杭电1518 Square(构成正方形) 搜索
HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- [LeetCode] 221. Maximal Square 最大正方形
Given a 2D binary matrix filled with 0's and 1's, find the largest square containing all 1's and ret ...
- Rectangle and Square
Description Little Petya very much likes rectangles and especially squares. Recently he has received ...
随机推荐
- .net单元测试——解除依赖
最近在看.net单元测试艺术,我也喜欢单元测试,这里写一下如何在测试中解除对象间的依赖. 假如有这样的一个需求,当用户登陆时,我需要对用户名和密码进行验证,然后再将用户名写入日志中. public c ...
- c语言学习之基础知识点介绍(六):if和switch结构
本节主要说c语言中的分支结构. c语言中分支结构有两大类:一种是if,一种是switch. 一.if结构 //if结构,语法: //第一种: if(表达式){ //语句块 } //第二种: if(表达 ...
- myeclipse10 中修改html,servlet,jsp等的生成模板
1.进入myeclipse的安装目录 2.用减压软件,(如winrar)打开common\plugins\com.genuitec.eclipse.wizards_9.0.0.me2011080913 ...
- SQL Server 损坏修复
目录: 一. 常见错误解读 二. DBCC CHECKDB 三 .不同部位损坏的应对 四. Database Mirroring和AlwaysOn的页面自动修复功能 一 常见错误解读 SQL Serv ...
- QueryString传值的加密与解密方法 .
//加密 Response.Redirect("DetailInfo.aspx?id=" + Convert.ToBase64String(System.Text.Encoding ...
- asp.net web api内部培训资料
最近在公司进行了一次asp.net web api的分享吧,不算是培训. 可能大家有些人对Web API的推出目的还不是很了解,可以看看微软官方的定义,其实是为了提供一个好的REST Service方 ...
- MVC5学习笔记
买了一本MVC5的书:ASP.NET MVC 5 高级编程(第5版).边学边记录一下 1.快速创建模型类,如:自动实现的属性 {get;set;} 输入“prop",按Tab两次,默认属性值 ...
- ScheduleThreadPoolExecutor源码分析
ScheduleThreadPoolExecutor源码分析(一) Java中ScheduleThreadPoolExecutor主要用于执行延迟任务或者按照一定的频率执行任务.其中scheduleA ...
- Mysql创建删除索引
1.查看某个表中的索引 show index from 表名 2.为某个表创建索引 alter table 表名 add index 索引名(列名) //此种方式创建一般的索引 alter ta ...
- 利用toString做类型的判断
//利用toString做类型的判断 : /*var arr = []; alert( Object.prototype.toString.call(arr) == '[object Array]' ...