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(判断正方形、矩形)的更多相关文章

  1. 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 ...

  2. bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*

    bzoj1661[Usaco2006 Nov]Big Square 巨大正方形 题意: n*n的图中有一些J点,一些B点和一些空白点,问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积.n≤ ...

  3. CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)

    题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...

  4. [LeetCode] Valid Square 验证正方形

    Given the coordinates of four points in 2D space, return whether the four points could construct a s ...

  5. [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 ...

  6. matlab-霍夫变换详解(判断正方形长方形)

    霍夫变换 霍夫变换是1972年提出来的,最开始就是用来在图像中过检测直线,后来扩展能检测圆.曲线等. 直线的霍夫变换就是 把xy空间的直线 换成成 另一空间的点.就是直线和点的互换. 我们在初中数学中 ...

  7. 杭电1518 Square(构成正方形) 搜索

    HDOJ1518 Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. [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 ...

  9. Rectangle and Square

    Description Little Petya very much likes rectangles and especially squares. Recently he has received ...

随机推荐

  1. spring参数类型异常输出(二), SpringMvc参数类型转换错误输出(二)

    spring参数类型异常输出(二), SpringMvc参数类型转换错误输出(二) >>>>>>>>>>>>>>&g ...

  2. PHP 基础语法 常量 变量

    PHP基础语法 标记 当解析一个文件时,PHP 会寻找起始和结束标记,也就是 <?php 和 ?>,这告诉 PHP 开始和停止解析二者之间的代码.此种解析方式使得 PHP 可以被嵌入到各种 ...

  3. MySQL数字类型中的三种常用种类

    数字类型 MySQL数字类型按照我的分类方法分为三类:整数类.小数类和数字类. MySQL数字类型之一我所谓的“数字类” 就是指 DECIMAL 和 NUMERIC,它们是同一种类型.它严格的说不是一 ...

  4. [序列化] SerializeHelper--序列化操作帮助类 (转载)

    点击下载 SerializeHelper.zip 这个类是关于加密,解密的操作,文件的一些高级操作1.XML序列化2.Json序列化3.SoapFormatter序列化4.BinaryFormatte ...

  5. 在.Net框架中 C# 实现多线程的同步方法详解

    本文主要描述在C#中线程同步的方法.线程的基本概念网上资料也很多就不再赘述了.直接接入主题,在多线程开发的应用中,线程同步是不可避免的.在.Net框架中,实现线程同步主要通过以下的几种方式来实现,在M ...

  6. oracle rowid 使用

    ROWID是数据的详细地址,通过rowid,oracle可以快速的定位某行具体的数据的位置. ROWID可以分为物理rowid和逻辑rowid两种.普通的堆表中的rowid是物理rowid,索引组织表 ...

  7. Struts2多文件上传

    第一步:首先创建一个多文件上传的页面 <html> <head> <meta http-equiv="Content-Type" content=&q ...

  8. Java SpringMvc+hibernate架构中,调用Oracle中的sp,传递数组参数

    一.问题 我们调用数据,大都是可以直接获取表中的数据,或者用复杂点的sql语句组成的.但是,有时候,当这样达不到我们要的全部数据的时候,这时,我们就用到了存储过程[sp],如果sp需要参数是数组的话, ...

  9. python文件操作汇总

    1.创建文件 f = open(filename,'w+')

  10. WPF常用控件应用demo

    WPF常用控件应用demo 一.Demo 1.Demo截图如下: 2.demo实现过程 总体布局:因放大缩小窗体,控件很根据空间是否足够改变布局,故用WrapPanel布局. <ScrollVi ...