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. centos7安装chrome的历程(fedora同)

    安装 首先是下载,地址奉上:http://www.google.cn/chrome/browser/desktop/index.html,选择64 bit .rpm (适用于 Fedora/openS ...

  2. SpringMVC注解@RequestMapping

        /**      * GET 查询      *      * @return 视图路径      */     @RequestMapping(value = {"/index&q ...

  3. centos could not retrieve mirrorlist

    centos could not retrieve mirrorlist >>>>>>>>>>>>>>>> ...

  4. Oracle REGEXP_INSTR 用法

    原文出处 ORACLE中的支持正则表达式的函数主要有下面四个:    1,REGEXP_LIKE :与LIKE的功能相似    2,REGEXP_INSTR :与INSTR的功能相似    3,REG ...

  5. What's DB2 模式?

    近期负责一个银行方面的项目,需要用到DB2实现多数据库版本切换.初步接触DB2,对于它的管理工具(IBM DATA STUDIO)虽然与ORACLE\MSSQL大同小异,但还是有些东西不一样的.比如什 ...

  6. Java5中的线程池实例讲解

    Java5增加了新的类库并发集java.util.concurrent,该类库为并发程序提供了丰富的API多线程编程在Java 5中更加容易,灵活.本文通过一个网络服务器模型,来实践Java5的多线程 ...

  7. pom.xml中<dependency>

    当想下载jar包时,需要在pom.xml追加<dependency>即可. 通过如下餐叙: 如下图 http://mvnrepository.com/artifact/cglib/cgli ...

  8. oracle set命令

    SQL>set colsep' ';     //-域输出分隔符SQL>set echo off;     //显示start启动的脚本中的每个sql命令,缺省为onSQL> set ...

  9. BOM 之 location

    BOM 之 location它提供了与当前窗口中加载的文档有关的信息,还提供一些导航功能 .既是 window对象的属性,也是document对象的属性,就是说, window.location 和 ...

  10. mysql的查询缓存模式介绍

    mysql的查询缓存 查询是数据库技术中最常用的操作.查询操作的过程比较简单,首先从客户端发出查询的SQL语句,数据库服务端在接收到由客户端发来的 SQL语句后, 执行这条SQL语句,然后将查询到的结 ...