Rectangle and Square
Description
Little Petya very much likes rectangles and especially squares. Recently he has received 8 points on the plane as a gift from his mother. The points are pairwise distinct. Petya decided to split them into two sets each containing 4 points so that the points from the first set lay at the vertexes of some square and the points from the second set lay at the vertexes of a rectangle. Each point of initial 8 should belong to exactly one set. It is acceptable for a rectangle from the second set was also a square. If there are several partitions, Petya will be satisfied by any of them. Help him find such partition. Note that the rectangle and the square from the partition should have non-zero areas. The sides of the figures do not have to be parallel to the coordinate axes, though it might be the case.
Input
You are given 8 pairs of integers, a pair per line — the coordinates of the points Petya has. The absolute value of all coordinates does not exceed 104. It is guaranteed that no tw
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;
int p[]={0,1,2,3,4,5,6,7,8};
int x[9],y[9];
int d(int a,int b)
{
return (x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b]);
}
int main()
{
int i,j;
for(i=1;i<=8;i++)scanf("%d%d",&x[i],&y[i]); do
{
if(d(p[1],p[2])==d(p[2],p[3]) && d(p[2],p[3])==d(p[3],p[4]) && d(p[3],p[4])==d(p[4],p[1]) && d(p[1],p[3])==d(p[4],p[2])
&& d(p[5],p[6])==d(p[7],p[8]) && d(p[5],p[8])==d(p[6],p[7]) && d(p[5],p[7])==d(p[6],p[8]))
{
return printf("YES\n%d %d %d %d\n%d %d %d %d\n",p[1],p[2],p[3],p[4],p[5],p[6],p[7],p[8]),0;
}
}while(next_permutation(p+1,p+9));
printf("NO\n");
return 0; }
o points coincide.
Output
Print in the first output line "YES" (without the quotes), if the desired partition exists. In the second line output 4 space-separated numbers — point indexes from the input, which lie at the vertexes of the square. The points are numbered starting from 1. The numbers can be printed in any order. In the third line print the indexes of points lying at the vertexes of a rectangle in the similar format. All printed numbers should be pairwise distinct.
If the required partition does not exist, the first line should contain the word "NO" (without the quotes), after which no output is needed.
Sample Input
0 0
10 11
10 0
0 11
1 1
2 2
2 1
1 2
YES
5 6 7 8
1 2 3 4
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
NO
0 0
4 4
4 0
0 4
1 2
2 3
3 2
2 1
YES
1 2 3 4
5 6 7 8
一开始不想敲,认为就是个全排列,没什么,网上搜了一下解题报告,确实是用全排列把所有的情况找出来,但是别人用了一个我认为非常吊的方法,调用stl里的全排列函数,屌爆了。
膜拜一下,STL里还有什么宝贝赶紧去找找。
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 ...
- CodeForces 135 B. Rectangle and Square(判断正方形和 矩形)
题目:http://codeforces.com/problemset/problem/135/B 题意:给8个点 判断能否用 4个点构成正方形,另外4个点构成 矩形. 输出 第一行是正方形 ,第二行 ...
- Rectangle and Square(判断正方形、矩形)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=42#problem/D 改了N多次之后终于A了,一直在改判断正方形和矩形那,判断 ...
- Matlab 进阶学习记录
最近在看 Faster RCNN的Matlab code,发现很多matlab技巧,在此记录: 1. conf_proposal = proposal_config('image_means', ...
- POJ 3449 Geometric Shapes --计算几何,线段相交
题意: 给一些多边形或线段,输出与每一个多边形或线段的有哪一些多边形或线段. 解法: 想法不难,直接暴力将所有的图形处理成线段,然后暴力枚举,相交就加入其vector就行了.主要是代码有点麻烦,一步一 ...
- RTTI (Run-Time Type Identification,通过运行时类型识别) 转
参考一: RTTI(Run-Time Type Identification,通过运行时类型识别)程序能够使用基类的指针或引用来检查这些指针或引用所指的对象的实际派生类型. RTTI提供了以下两个 ...
- An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习
# Practice Exercises for Functions # Solve each of the practice exercises below. # 1.Write a Python ...
- cdoj 93 King's Sanctuary 傻逼几何题
King's Sanctuary Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/problem/sho ...
- C++中str1::function和bind
在C++的TR1中(TechnologyReport)中包括一个function模板类和bind模板函数,使用它们能够实现类似函数指针的功能,但却却比函数指针更加灵活,特别是函数指向类的非静态成员函数 ...
随机推荐
- Unix/Linux环境C编程入门教程(40) 初识文件操作
1.函数介绍 close(关闭文件) 相关函数 open,fcntl,shutdown,unlink,fclose 表头文件 #include<unistd.h> 定义函数 int ...
- Grunt 插件开发与调式
1 grunt是什么 官方网站解释的很清楚,http://gruntjs.com/ http://gruntjs.cn/ 它是一种javascript任务运行器,对于需要反复重复的任务,例如压缩.编译 ...
- Unity 功夫猫
最近在家里闲着蛋疼,突然看到一个HTML游戏感觉挺可爱的,就把素材拿过来自己写了一遍. 游戏有很多细节还是没有模仿出来. 里面有一个2DUGUI帧动画播放插件,写了我3个通宵. 还是对Unity的扩展 ...
- ios block使用
BlockTest.h #import <Foundation/Foundation.h> typedef void (^didFinishBlock)(NSString *str); t ...
- 基础总结篇之九:Intent应用详解
看似尋常最奇崛,成如容易卻艱辛.北宋.王安石 看似普通的事情其实最不同寻常,并不是简简单单就可以做好的:成功看起来似乎很容易,而成功的过程却充满着艰辛. 对于我们认为很普通的事情,不屑一顾,就永远不会 ...
- [转载]Vertica “ERROR: Too many ROS containers exist”
最近在用Vertica的时候碰到一个问题,Vertica在运行了一段时间后总是出现类似下面的错误 1: java.sql.SQLException: [Vertica][VJDBC](5065) 2: ...
- python学习之路-13
SQLAlchemy ORM框架 连表操作 一对多 创建表 指定约束 ForeignKey from sqlalchemy import create_engine from sqlalchemy.e ...
- mycat实例(3)
配置MyCat 4. 配置schema.xml schema.xml里面管理着MyCat的逻辑库.表,每张表使用的分片规则.分布在哪个DataNode以及DataSource上. 之前的例子: < ...
- 关于MemoryBarrier
备注:OSG OpenThread::Atomic.cpp中MemoryBarrier(); Atomic::operator unsigned() const { #if defined(_OPE ...
- 2014 (多校)1011 ZCC Loves Codefires
自从做了多校,整个人都不好了,老是被高中生就算了,题老是都不懂=-=原谅我是个菜鸟,原谅我智力不行.唯一的水题. Problem Description Though ZCC has many Fan ...