C. Captain Marmot (Codeforces Round #271)
来源:互联网 发布:lims系统数据接口 编辑:程序博客网 时间:2024/06/06 03:12
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.
The first line contains one integer n (1 ≤ n ≤ 100), the number of regiments.
The next 4n lines contain 4 integers xi, yi, ai, bi ( - 104 ≤ xi, yi, ai, bi ≤ 104).
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).
41 1 0 0-1 1 0 0-1 1 0 01 -1 0 01 1 0 0-2 1 0 0-1 1 0 01 -1 0 01 1 0 0-1 1 0 0-1 1 0 0-1 1 0 02 2 0 1-1 0 0 -23 0 0 -2-1 1 -2 0
1-133
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)
- Captain Marmot(Codeforces Round #271 div2) C
- Codeforces Round #271 (Div. 2) C. Captain Marmot
- 【CODEFORCES】 C. Captain Marmot
- Codeforces 474 C. Captain Marmot
- CodeForces 474C - Captain Marmot
- Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)
- codeforces 474c C. Captain Marmot
- codeforces 474C Captain Marmot dfs
- Codeforces 474c Captain Marmot | 暴力几何
- 【Codeforces Round 271 (Div 2)C】【暴力 坐标变换】Captain Marmot 四个点绕中心旋转 最小步数使得构成正方形
- Codeforces 474C Captain Marmot 暴力+几何(绕定点旋转)
- CF 474C Captain Marmot
- CF 271 A Keyboard B Worms C Captain Marmot
- Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数
- CF 474C Captain Marmot[暴力枚举 || bfs状态压缩 ]
- Codeforces Round #366 (Div. 1) D Captain America 网络流
- Codeforces Round #271 (Div. 2) C
- UVA - 10916 Factstone Benchmark
- 4G频谱分配
- JPEG压缩算法流程
- TCP/IP协议栈--IP首部选项字段的分析
- 计算机视觉领域的一些牛人博客,超有实力的研究机构等的网站链接
- C. Captain Marmot (Codeforces Round #271)
- Git(四):理解和使用分支
- nyoj448--寻找最大数
- JavaScript数组对象根据索引(index)删除元素
- Linux词典安装
- eclipse中svn插件的安装
- iPhone开发经典语录集锦
- NHibernate 3.3.3GA
- POJ Farm Tour