codeforces 474C Captain Marmot dfs
来源:互联网 发布:网络直播收入排名 编辑:程序博客网 时间:2024/06/01 09:40
传送门:cf 474c
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度,问这四个点最少旋转多少次能构成一个正方形。
每个点旋转4次就回到自身状态了,因此加上初始状态就只有4^4种状态,dfs枚举状态判断是否是正方形即可
/****************************************************** * File Name: c.cpp * Author: kojimai * Creater Time:2014年10月07日 星期二 01时14分52秒******************************************************/#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<iostream>using namespace std;struct node{int a,b,x,y;}p[5],aa[5];int ans;void rotate(int now){int x = aa[now].y - aa[now].b + aa[now].x;int y = aa[now].a - aa[now].x + aa[now].y;aa[now].a = x;aa[now].b = y;}bool judge(){int t,x,y,cnt=0;for(int i = 0;i < 4;i++){for(int j = i+1;j < 4;j++){if(aa[i].a==aa[j].a&&aa[i].b==aa[j].b)return false;t = (aa[i].a - aa[j].a)*(aa[i].a - aa[j].a) + (aa[i].b - aa[j].b) * (aa[i].b - aa[j].b);if(cnt==0){cnt = 1;x = t;}else if(cnt == 1){if(t != x){cnt = 2;y = t;}}else if(cnt == 2){if(t != x && t != y)return false;}}}return true;}void dfs(int now,int num){//cout<<"now="<<now<<" num="<<num<<" ans="<<ans<<endl;if(num >= ans)return;if(now==4){if(judge())ans = num;return;}aa[now] = p[now];for(int i=0;i<4;i++){if(i){rotate(now);dfs(now+1,num+i);}elsedfs(now+1,num);}}int main(){int n;scanf("%d",&n);while(n--){for(int i=0;i<4;i++)scanf("%d%d%d%d",&p[i].a,&p[i].b,&p[i].x,&p[i].y);ans = 16;dfs(0,0);if(ans == 16)ans = -1;cout<<ans<<endl;}return 0;}
- codeforces 474C Captain Marmot dfs
- Codeforces 474 C. Captain Marmot
- CodeForces 474C - Captain Marmot
- 【CODEFORCES】 C. Captain Marmot
- codeforces 474c C. Captain Marmot
- Codeforces 474c Captain Marmot | 暴力几何
- CF 474C Captain Marmot
- Codeforces 474C Captain Marmot 暴力+几何(绕定点旋转)
- C. Captain Marmot (Codeforces Round #271)
- Captain Marmot(Codeforces Round #271 div2) C
- Codeforces Round #271 (Div. 2) C. Captain Marmot
- CF 474C Captain Marmot[暴力枚举 || bfs状态压缩 ]
- Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数
- Codeforces Round #271 (Div. 2) C. Captain Marmot (暴力枚举+正方形判定)
- CF 271 A Keyboard B Worms C Captain Marmot
- 【Codeforces Round 271 (Div 2)C】【暴力 坐标变换】Captain Marmot 四个点绕中心旋转 最小步数使得构成正方形
- Codeforces 744C【DFS】
- Codeforces 369C DFS
- 爱妃阿散井安科技快乐讲啊
- HDU 4565 So Easy!(矩阵快速幂)
- Replica Island 学习笔记 04 - AndouKun
- Android解耦库EventBus的使用和源码分析
- 字节对齐
- codeforces 474C Captain Marmot dfs
- java的重写、重载、覆盖的区别
- accelerated c++答案(自写)---第三章
- C#-—体验字段
- UBuntu安裝使用PIP
- Android Launcher3壁纸居中问题
- 关于 sprintf,关于类型安全。
- stardict安装
- 【java】java.awt基础(简易记事本代码)