CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)
题目:http://codeforces.com/problemset/problem/135/B
题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形。
输出 第一行是正方形 ,第二行是矩形。
我的思路:用了4个for循环 枚举四个点, 用向量判断,四个点构成 六条边,如果这六条边里,
有四条边 与他们垂直的边有两个,就说明是矩形,在这个基础上,有 2条边 与他们垂直的边有一个。
说明是正方形。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std; struct point
{
int x,y;
} p[10];
int check(point a,point b,point c,point d)
{
int i,j,sumt=0,sumo=0;
int px[10],py[10];//代表6条边的 向量
int y[10];
memset(y,0,sizeof(y));
px[1]=a.x-b.x;
py[1]=a.y-b.y;
px[2]=a.x-c.x;
py[2]=a.y-c.y;
px[3]=a.x-d.x;
py[3]=a.y-d.y;
px[4]=b.x-c.x;
py[4]=b.y-c.y;
px[5]=b.x-d.x;
py[5]=b.y-d.y;
px[6]=c.x-d.x;
py[6]=c.y-d.y;
for(i=1; i<=6; i++)
{
for(j=i+1; j<=6; j++)
if((px[i]*px[j]+py[i]*py[j])==0)//判断垂直
{
y[i]++;
y[j]++;
}
}
for(i=1; i<=6; i++)
{
if(y[i]==2)
sumt++;//有2条边 与其垂直的个数
if(y[i]==1)
sumo++;//有1条边 与其垂直的个数
}
if(sumt==4&&sumo==2)
return 2;// 是正方形
if(sumt==4)
return 1;//是 矩形
return 0;//都不是
}
int main()
{
int i,j,k,l,ans,f,m;
int i2,j2,k2,l2;
int b[10],y;
while(cin>>p[1].x>>p[1].y)
{
f=0;
for(i=2; i<=8; i++)
cin>>p[i].x>>p[i].y;
for(i=1; i<=5; i++)
{
for(j=i+1; j<=6; j++)
{
for(k=j+1; k<=7; k++)
{
for(l=k+1; l<=8; l++)
{
ans=check(p[i],p[j],p[k],p[l]);
if(ans==0)
continue;
if(ans==2)//当前是正方形时
{
y=1;
for(m=1; m<=8; m++)
{
if(m!=i&&m!=j&&m!=k&&m!=l)
b[y++]=m;
}
i2=b[1];
j2=b[2];
k2=b[3];
l2=b[4]; ans=check(p[i2],p[j2],p[k2],p[l2]);//看是否 剩下的点是矩形
if(ans)
{
f=1;
break;
}
}
}
if(f)
break;
}
if(f) break;
}
if(f) break;
}
if(f)
{
cout<<"YES"<<endl;
printf("%d %d %d %d\n",i,j,k,l);
printf("%d %d %d %d\n",i2,j2,k2,l2);
}
else
cout<<"NO"<<endl;
}
return 0;
}
CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)的更多相关文章
- Rectangle and Square(判断正方形、矩形)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...
- 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 ...
- 判断圆和矩形是否相交C - Rectangle and Circle
Description Given a rectangle and a circle in the coordinate system(two edges of the rectangle are p ...
- HDU 1221 Rectangle and Circle(判断圆和矩形是不是相交)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1221 Rectangle and Circle Time Limit: 2000/1000 MS (J ...
- Codeforces Round #587 (Div. 3) C题 【判断两个矩形是否完全覆盖一个矩形问题】 {补题 [差点上分系列]}
C. White Sheet There is a white sheet of paper lying on a rectangle table. The sheet is a rectangle ...
- bzoj1661[Usaco2006 Nov]Big Square 巨大正方形*
bzoj1661[Usaco2006 Nov]Big Square 巨大正方形 题意: n*n的图中有一些J点,一些B点和一些空白点,问在空白点添加一个J点所能得到的有4个J点组成最大正方形面积.n≤ ...
- poj 1410 Intersection (判断线段与矩形相交 判线段相交)
题目链接 Intersection Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12040 Accepted: 312 ...
- python3 turtle画正方形、矩形、正方体、五角星、奥运五环
python3 环境 turtle模块 分别画出 正方形.矩形.正方体.五角星.奥运五环 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:H ...
- Intersection--poj1410(判断线段与矩形的关系)
http://poj.org/problem?id=1410 题目大意:给你一个线段和矩形的对角两点 如果相交就输出'T' 不想交就是'F' 注意: 1,给的矩形有可能不是左上 右下 所以要先判 ...
随机推荐
- jquery返回顶部特效
<style> p#back-to-top{position:fixed; bottom:100px;right:10px; display: none; } p#back-to-top ...
- Spring Cloud OAuth
In this blog post we will create a secure API for external access, using OAuth 2.0, to the microserv ...
- dbt
Procedure Relocate(s : state; b : base_index) { Move base for state s to a new place beginning at b ...
- Think PHP 提示验证码输入错误
最近遇到一个项目中用的是Thinkphp这个框架开发的,其中在登录这块有验证码这个功能,其实这个功能是TP自带的,其中主要方法是buildImageVerify,位于ThinkPHP\Extend\L ...
- PyQt4学习记录之事件和信号
事件是任何 GUI程序中很重要的部分.所有 Python GUI 应用都是事件驱动的.一个应用对其生命期产生的不同的事件类型做出反应.事件是主要由应用的用户产生.但是,也可以通过其他方法产生,比如,网 ...
- jsp日期控件My97DatePicker的使用
My97DatePicker是一款非常灵活好用的日期控件.使用非常简单. 1.下载My97DatePicker组件包 2.将My97DatePicker包放在项目WebContent目录下 3.在页面 ...
- DOM初涉
document documentURI, URL 返回当前网页的URL(String) activeElement 返回当前得到焦点的标签,input, textarea等比较常见,否则返回body ...
- 利用PHPRPC以及SOAP分别实现PHP的Webserver功能
服务端:phprpc服务端 <?php /* phprpc 服务端演示 * time:2014-06-23 */ require_once 'phprpc_server.php';//引入服务端 ...
- Bootstrap 内核引用(一)
方法一: Bootstrap CDN推荐 本站实例采用的是百度的静态资源库(http://cdn.code.baidu.com/)上的Bootstrap资源. 百度的静态资源库的 CDN 服务,访问速 ...
- iOS 基础 第二天(0805)
0805 面向对象三大特性 封装.继承和多态 oc的方法都是在运行过程中才会检测的.编译时方法没实现只会出现警告,运行时出错.如果方法实现了但没有声明,运行时对象仍然可以调用方法不会出错.这是OC中弱 ...