【CODEFORCES】 C. Captain Marmot
2015-07-22 10:17
459 查看
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 xi, yi, ai, bi ( - 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
output
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个一组,每个点可以绕某点逆时针旋转,问最后能否组成一个正方形。
直接暴力出所有可能情况,然后判断是否为正方形就行了。(判断正方形的时候参考了下别人的代码= =)
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 xi, yi, ai, bi ( - 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; }
相关文章推荐
- 如何使用Jmail组件实现邮件的收发
- 03-树3. Tree Traversals Again (25)
- 【线段树】2015 Multi-University Training Contest 1 1002
- 【数论】2015 Multi-University Training Contest 1 1001
- hdu 5291 Candy Distribution 2015 Multi-University Training Contest 1
- grails domain创建相关问题
- 深入解析alloc/retain/release/dealloc实现
- hdu1151 二分图(无回路有向图)的最小路径覆盖 Air Raid
- ubuntu 10.10 drcom成功上网 好不容易。附:_recv_dialog_packet(PKT_CHALLENGE) failed解决之道
- URL validation failed. The error could have been caused through the use of the browser's navigation
- bailian.openjudge.cn2705
- VT.Essay.1:Try again. Fail again. Fail better.
- Russell's Paradox: Here's Why Maths Can't Have A Set Of Everything
- HDU 5289 Assignment (2015 Multi-University Training Contest 1)
- HDU5294 Tricks Device(最大流+SPFA) 2015 Multi-University Training Contest 1
- Copy,mutableCopy和retain的区别的小理解
- 2015 Multi-University Training Contest 1 题解 BY FZUw
- service是否在main thread中执行, service里面是否能执行耗时的操作?
- MFC学习笔记.day01-WINMAIN,MSG,WNDCLASS,ID-HANDLE-HWND,图标光标
- hdu 2473 Junk-Mail Filter(并查集(虚拟父节点))