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.

题解:这一题就是给你8*n个点,每4个一组,每一个点能够绕某点逆时针旋转,问最后是否能组成一个正方形。

直接暴力出全部可能情况。然后推断是否为正方形即可了。

(推断正方形的时候參考了下别人的代码= =)

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib> using namespace std; struct dir
{
int x,y;
}; struct dir d[4][4],h[4]; long long dis[10]; long long dist(long long x1,long long y1,long long x2,long long y2)
{
return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
} int n,ans; int main()
{
scanf("%d",&n);
while (n--)
{
memset(d,0,sizeof(d));
memset(h,0,sizeof(h));
for (int i=0;i<4;i++) scanf("%d%d%d%d",&d[i][0].x,&d[i][0].y,&h[i].x,&h[i].y);
for (int i=0;i<4;i++)
for (int j=1;j<4;j++)
{
d[i][j].x=h[i].x+h[i].y-d[i][j-1].y;
d[i][j].y=d[i][j-1].x-h[i].x+h[i].y;
}
ans=16;
for (int i=0;i<4;i++)
{
for (int j=0;j<4;j++)
for (int k=0;k<4;k++)
for (int z=0;z<4;z++)
{
memset(dis,0,sizeof(dis));
dis[0]=dist(d[0][i].x,d[0][i].y,d[1][j].x,d[1][j].y);
dis[1]=dist(d[1][j].x,d[1][j].y,d[2][k].x,d[2][k].y);
dis[2]=dist(d[2][k].x,d[2][k].y,d[3][z].x,d[3][z].y);
dis[3]=dist(d[3][z].x,d[3][z].y,d[0][i].x,d[0][i].y);
dis[4]=dist(d[0][i].x,d[0][i].y,d[2][k].x,d[2][k].y);
dis[5]=dist(d[1][j].x,d[1][j].y,d[3][z].x,d[3][z].y);
sort(dis,dis+6);
if (dis[0]==dis[1] && dis[1]==dis[2] && dis[2]==dis[3] && dis[3]==dis[0] && 2*dis[0]==dis[5] && dis[5]==dis[4] && dis[0])
ans=min(ans,i+j+k+z);
}
}
if (ans==16) printf("-1\n");
else printf("%d\n",ans);
}
return 0;
}

【CODEFORCES】 C. Captain Marmot的更多相关文章

  1. 【BZOJ4152】The Captain(最短路)

    [BZOJ4152]The Captain(最短路) 题面 BZOJ Description 给定平面上的n个点,定义(x1,y1)到(x2,y2)的费用为min(|x1-x2|,|y1-y2|),求 ...

  2. 【Codeforces】Round #491 (Div. 2) 总结

    [Codeforces]Round #491 (Div. 2) 总结 这次尴尬了,D题fst,E没有做出来.... 不过还好,rating只掉了30,总体来说比较不稳,下次加油 A:If at fir ...

  3. 【Codeforces】Round #488 (Div. 2) 总结

    [Codeforces]Round #488 (Div. 2) 总结 比较僵硬的一场,还是手速不够,但是作为正式成为竞赛生的第一场比赛还是比较圆满的,起码没有FST,A掉ABCD,总排82,怒涨rat ...

  4. 【CodeForces】601 D. Acyclic Organic Compounds

    [题目]D. Acyclic Organic Compounds [题意]给定一棵带点权树,每个点有一个字符,定义一个结点的字符串数为往下延伸能得到的不重复字符串数,求min(点权+字符串数),n&l ...

  5. 【Codeforces】849D. Rooter's Song

    [算法]模拟 [题意]http://codeforces.com/contest/849/problem/D 给定n个点从x轴或y轴的位置p时间t出发,相遇后按对方路径走,问每个数字撞到墙的位置.(还 ...

  6. 【CodeForces】983 E. NN country 树上倍增+二维数点

    [题目]E. NN country [题意]给定n个点的树和m条链,q次询问一条链(a,b)最少被多少条给定的链覆盖.\(n,m,q \leq 2*10^5\). [算法]树上倍增+二维数点(树状数组 ...

  7. 【CodeForces】925 C.Big Secret 异或

    [题目]C.Big Secret [题意]给定数组b,求重排列b数组使其前缀异或和数组a单调递增.\(n \leq 10^5,1 \leq b_i \leq 2^{60}\). [算法]异或 为了拆位 ...

  8. 【CodeForces】700 D. Huffman Coding on Segment 哈夫曼树+莫队+分块

    [题目]D. Huffman Coding on Segment [题意]给定n个数字,m次询问区间[l,r]的数字的哈夫曼编码总长.1<=n,m,ai<=10^5. [算法]哈夫曼树+莫 ...

  9. 【CodeForces】906 D. Power Tower 扩展欧拉定理

    [题目]D. Power Tower [题意]给定长度为n的正整数序列和模数m,q次询问区间[l,r]累乘幂%m的答案.n,q<=10^5,m,ai<=10^9. [算法]扩展欧拉定理 [ ...

随机推荐

  1. 洛谷P3926 SAC E#1 - 一道不可做题 Jelly【模拟/细节】

    P3926 SAC E#1 - 一道不可做题 Jelly [链接]:https://www.luogu.org/problem/show?pid=3926 题目背景 SOL君(炉石主播)和SOL菌(完 ...

  2. (转载)UIKIt力学教程

    转载自:http://www.cocoachina.com/ios/20131226/7614.html 这篇文章还可以在这里找到 英语,   Ray:这篇教程节选自 iOS 7 教程集,它是 iOS ...

  3. 【分块】bzoj3295 [Cqoi2011]动态逆序对

    考虑每次删除pos位置一个数x后,所造成的的影响就是,逆序对的个数少了在1~pos-1中大于x的数的个数加上pos+1~n中小于x的数的个数. 那么我们需要的操作就只有查询区间内比某数大(小)的个数. ...

  4. 读取SequenceFile中自定义Writable类型值

    1)hadoop允许程序员创建自定义的数据类型,如果是key则必须要继承WritableComparable,因为key要参与排序,而value只需要继承Writable就可以了.以下定义一个Doub ...

  5. Spring Boot企业微信点餐系统-第一章-课程介绍

    一.项目简介——技术要点 前端和后端: 后端主要技术: 微信接口技术 微信支付 微信扫码登录 微信模板消息推送 开发环境 但实际上我用的环境和这上面还是有点不一样,我服务器用的是win,到时候我会详细 ...

  6. JavaScript:this是什么

    JavaScript:this是什么? 定义:this是包含它的函数作为方法被调用时所属的对象. 说明:这句话有点咬嘴,但一个多余的字也没有,定义非常准确,我们可以分3部分来理解它! 1.包含它的函数 ...

  7. Activiti 5.22 spring

    <!-- activiti依赖 --> <dependency> <groupId>org.activiti</groupId> <artifac ...

  8. sqlmap批量扫描burpsuite拦截的日志记录

    1.功能上,sqlmap具备对burpsuite拦截的request日志进行批量扫描的能力 python sqlmap.py -l hermes.log --batch -v 3 --batch:会自 ...

  9. 《linux 内核全然剖析》 chapter 4 80x86 保护模式极其编程

    80x86 保护模式极其编程       首先我不得不说.看这章真的非常纠结...看了半天.不知道这个东西能干嘛.我感觉唯一有点用的就是对于内存映射的理解...我假设不在底层给80x86写汇编的话.我 ...

  10. Java遍历总结:for、for each和迭代器iterator

    一.for,for each和iterator用法和区别: 相同点:   三个都可以用来遍历数组和集合 不同点: 1.形式差别 //for的形式是 ;i<arr.size();i++){...} ...