C. Captain Marmot
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Captain Marmot wants to prepare a huge and important battle against his enemy, Captain Snake. For this battle he has n regiments, each consisting of 4 moles.

Initially, each mole i (1 ≤ i ≤ 4n) is placed
at some position (xi, yi) in
the Cartesian plane. Captain Marmot wants to move some moles to make the regiments compact, if it's possible.

Each mole i has a home placed at the position (ai, bi).
Moving this mole one time means rotating his position point (xi, yi) 90 degrees
counter-clockwise around it's home point (ai, bi).

A regiment is compact only if the position points of the 4 moles form a square with non-zero area.

Help Captain Marmot to find out for each regiment the minimal number of moves required to make that regiment compact, if it's possible.

Input

The first line contains one integer n (1 ≤ n ≤ 100),
the number of regiments.

The next 4n lines contain 4 integers xiyiaibi ( - 104 ≤ xi, yi, ai, bi ≤ 104).

Output

Print n lines to the standard output. If the regiment i can
be made compact, the i-th line should contain one integer, the minimal number of required moves. Otherwise, on the i-th
line print "-1" (without quotes).

Sample test(s)
input
4
1 1 0 0
-1 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-2 1 0 0
-1 1 0 0
1 -1 0 0
1 1 0 0
-1 1 0 0
-1 1 0 0
-1 1 0 0
2 2 0 1
-1 0 0 -2
3 0 0 -2
-1 1 -2 0
output
1
-1
3
3
Note

In the first regiment we can move once the second or the third mole.

We can't make the second regiment compact.

In the third regiment, from the last 3 moles we can move once one and twice another one.

In the fourth regiment, we can move twice the first mole and once the third mole.

四个点绕给定的中心点逆时针旋转90度,看能否构成正方形,若能。输出最小旋转次数。

每一个点最多旋转3次。4次则回到了原来的位置。就能够用个二维数组把每一个状态记录下来。最后再推断一下是

否能构成正方形即可了。

代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
const int inf=9999999;
using namespace std;
struct node
{
int x;
int y;
}p[5][5],home[5];
long long d[8];
long long dis(node a,node b)//距离的平方
{
return (long long)(a.x-b.x)*(a.x-b.x)+(long long)(a.y-b.y)*(a.y-b.y);
}
void solve()
{
int ans=inf;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
for(int k=0;k<4;k++)
{
for(int l=0;l<4;l++)
{
d[0]=dis(p[i][0],p[j][1]);//四边距离的平方
d[1]=dis(p[j][1],p[k][2]);
d[2]=dis(p[k][2],p[l][3]);
d[3]=dis(p[l][3],p[i][0]);
d[4]=dis(p[i][0],p[k][2]);//对角线的平方
d[5]=dis(p[j][1],p[l][3]); sort(d,d+6);
if(d[0]==0)
continue;
else if(d[0]==d[1]&&d[1]==d[2]&&d[2]==d[3]&&2*d[3]==d[4]&&d[4]==d[5])//推断是否为正方形
{
ans=min(ans,i+j+k+l);
}
}
}
}
}
if(ans!=inf)
printf("%d\n",ans);
else
printf("-1\n");
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
for(int i=0;i<4;i++)
{
scanf("%d%d",&p[0][i].x,&p[0][i].y);
scanf("%d%d",&home[i].x,&home[i].y);
int x=p[0][i].x-home[i].x;
int y=p[0][i].y-home[i].y; p[1][i].x=home[i].x-y;//逆时针旋转90度
p[1][i].y=home[i].y+x; p[2][i].x=home[i].x-x;
p[2][i].y=home[i].y-y; p[3][i].x=home[i].x+y;
p[3][i].y=home[i].y-x;
}
solve();
}
return 0;
}



版权声明:本文博主原创文章,博客,未经同意不得转载。

C. Captain Marmot (Codeforces Round #271)的更多相关文章

  1. Codeforces Round #271 (Div. 2)题解【ABCDEF】

    Codeforces Round #271 (Div. 2) A - Keyboard 题意 给你一个字符串,问你这个字符串在键盘的位置往左边挪一位,或者往右边挪一位字符,这个字符串是什么样子 题解 ...

  2. Codeforces Round #271 (Div. 2) 解题报告

    题目地址:http://codeforces.com/contest/474 A题:Keyboard 模拟水题. 代码例如以下: #include <iostream> #include ...

  3. Codeforces Round #271 (Div. 2)

    A. Keyboard 题意:一个人打字,可能会左偏一位,可能会右偏一位,给出一串字符,求它本来的串 和紫书的破损的键盘一样 #include<iostream> #include< ...

  4. 「日常训练」Watering Flowers(Codeforces Round #340 Div.2 C)

    题意与分析 (CodeForces 617C) 题意是这样的:一个花圃中有若干花和两个喷泉,你可以调节水的压力使得两个喷泉各自分别以\(r_1\)和\(r_2\)为最远距离向外喷水.你需要调整\(r_ ...

  5. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

  6. 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)

    题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...

  7. 「日常训练」Duff in the Army (Codeforces Round #326 Div.2 E)

    题意(CodeForces 588E) 给定一棵\(n\)个点的树,给定\(m\)个人(\(m\le n\))在哪个点上的信息,每个点可以有任意个人:然后给\(q\)个询问,每次问\(u\)到\(v\ ...

  8. 「日常训练」Kefa and Dishes(Codeforces Round #321 Div. 2 D)

    题意与分析(CodeForces 580D) 一个人有\(n\)道菜,然后要点\(m\)道菜,每道菜有一个美味程度:然后给你了很多个关系,表示如果\(x\)刚好在\(y\)前面做的话,他的美味程度就会 ...

  9. 「日常训练」Kefa and Park(Codeforces Round #321 Div. 2 C)

    题意与分析(CodeForces 580C) 给你一棵树,然后每个叶子节点会有一家餐馆:你讨厌猫(waht?怎么会有人讨厌猫),就不会走有连续超过m个节点有猫的路.然后问你最多去几家饭店. 这题我写的 ...

随机推荐

  1. QTableView 固定列宽度(鼠标拖动后,仍可固定)

    QTableView 提供一个函数: void QTableView::setColumnWidth ( int column, int width ) 用于设置column指定的列的宽度 但setC ...

  2. newlisp 注释生成文档

    最近写了一个newlisp_armory库,用来实现一些newlisp自身不支持的操作.比如跨windows和ubuntu的目录拷贝功能等. 自己用的时候,发现没有API reference文档参考, ...

  3. hadoop集群空间使用情况报告脚本

    近期集群空间有点紧张,总是操心空间不足而崩溃,近期扩容又不太现实,经与集群用户沟通发现:集群上存储了非常多没用的历史数据,能够删除,这样就能够通过一个crontab脚本每天生成集群空间使用报告,当使用 ...

  4. android新浪分享实例

    新浪分享比较简单,新浪有提供完整的demo. android实现新浪的分享功能,分3种分享情况: 纯文本的,带图片的,图片为本地图片(传入的是图片在手机的地址),第2种带图片的是,网络图片,图片地址为 ...

  5. 苹果iOS手机系统诊断功能是后门吗?

    7月20日,美国知名苹果iOS手机系统侦破专家扎德尔斯基在2014年世界黑客大会(HOPE/X)用幻灯片讲演揭露了苹果手机存在系统级"后门". 为此,7月23日.苹果公司马上做出回 ...

  6. 23、Cocos2dx 3.0游戏开发找小三之粒子系统:你那里下雪了吗?

    重开发人员的劳动成果.转载的时候请务必注明出处:http://blog.csdn.net/haomengzhu/article/details/30485919 春雨惊春清谷天,夏满芒夏暑相连, 秋处 ...

  7. 【Java】运用JDBC实现一个注册、登录系统的编写

    数据库的建立 首先,建立一个数据库,存储注册成功的账户信息. 其SQL的DDL语句如下: CREATE TABLE `jdbctest` ( `id` int(10) NOT NULL auto_in ...

  8. 使用GraceNote Web API发展Mac发现音乐信息的应用

    好久没有写博客,最近各种忙,特别忙里忙,今晚难得清闲.写最近完成下一个博客任务的摘要:使用GraceNote的Web API开发一个查询的音乐信息的应用,事实上,并在这些功能的前GraceNote S ...

  9. VC++ 在两个文件互相包含时会出现的错误

    首先,要分别在两个文件中实现以下两个类 class Object { public: NewType ToType(); }; class NewType : public Object { } -- ...

  10. java获取当前日期时间代码总结

    1.获取当前时间,和某个时间进行比较.此时主要拿long型的时间值.  方法如下: 要使用 java.util.Date .获取当前时间的代码如下  代码如下 复制代码 Date date = new ...