CodeForces 474C - Captain Marmot
来源:互联网 发布:图片分割打印软件 编辑:程序博客网 时间:2024/06/05 17:07
题意:每组共4个点,4个点分别有起始坐标和轴心坐标,每个点每次都可以绕自己的轴心坐标90°,问能否用最少次数内4个点组成一个正方形,若能则输出最少次数,否则输出-1。
每个点有4个方位可以选择,共4个点,4 * 4 * 4 * 4 = 256种,暴力即可
#include<cstdio>#include<cstring>#include<cstdlib>#include<cctype>#include<cmath>#include<iostream>#include<sstream>#include<iterator>#include<algorithm>#include<string>#include<vector>#include<set>#include<map>#include<stack>#include<deque>#include<queue>#include<list>typedef long long ll;typedef unsigned long long llu;const int MAXN = 100 + 10;const int MAXT = 10000 + 10;const int INF = 0x7f7f7f7f;const double pi = acos(-1.0);const double eps = 1e-6;using namespace std;struct Point{ int x, y; bool operator < (const Point &b) const{ return x < b.x || (y < b.y && x == b.x); } Point(int a = 0, int b = 0) : x(a), y(b) {} Point(const Point &b) : x(b.x), y(b.y) {} Point& operator = (const Point &b){ x = b.x; y = b.y; return *this; }}p[5];int xx[5], yy[5], a[5], b[5];Point f1(int x, int y, int ox, int oy){ return Point(x, y);}Point f2(int x, int y, int ox, int oy){ return Point(ox + oy - y, oy - ox + x);}Point f3(int x, int y, int ox, int oy){ return Point(2 * ox - x, 2 * oy - y);}Point f4(int x, int y, int ox, int oy){ return Point(y - oy + ox, ox - x + oy);}bool judge(){ sort(p, p + 4); int c1x = p[1].x - p[0].x; int c1y = p[1].y - p[0].y; int c1 = c1x * c1x + c1y * c1y; int c2x = p[2].x - p[0].x; int c2y = p[2].y - p[0].y; int c2 = c2x * c2x + c2y * c2y; int c3x = p[3].x - p[2].x; int c3y = p[3].y - p[2].y; int c3 = c3x * c3x + c3y * c3y; int c4x = p[3].x - p[1].x; int c4y = p[3].y - p[1].y; int c4 = c4x * c4x + c4y * c4y; if(c1 == c2 && c2 == c3 && c3 == c4){ if(c1x * c2x + c1y * c2y == 0 && c2x * c3x + c2y * c3y == 0 && c3x * c4x + c3y * c4y == 0 && (p[0].x != p[1].x || p[0].y != p[1].y)) return true; } return false;}int main(){ int T; scanf("%d", &T); while(T--){ for(int i = 0; i < 4; ++i) scanf("%d%d%d%d", &xx[i], &yy[i], &a[i], &b[i]); 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){ if(i == 0) p[0] = f1(xx[0], yy[0], a[0], b[0]); else if(i == 1) p[0] = f2(xx[0], yy[0], a[0], b[0]); else if(i == 2) p[0] = f3(xx[0], yy[0], a[0], b[0]); else if(i == 3) p[0] = f4(xx[0], yy[0], a[0], b[0]); if(j == 0) p[1] = f1(xx[1], yy[1], a[1], b[1]); else if(j == 1) p[1] = f2(xx[1], yy[1], a[1], b[1]); else if(j == 2) p[1] = f3(xx[1], yy[1], a[1], b[1]); else if(j == 3) p[1] = f4(xx[1], yy[1], a[1], b[1]); if(k == 0) p[2] = f1(xx[2], yy[2], a[2], b[2]); else if(k == 1) p[2] = f2(xx[2], yy[2], a[2], b[2]); else if(k == 2) p[2] = f3(xx[2], yy[2], a[2], b[2]); else if(k == 3) p[2] = f4(xx[2], yy[2], a[2], b[2]); if(l == 0) p[3] = f1(xx[3], yy[3], a[3], b[3]); else if(l == 1) p[3] = f2(xx[3], yy[3], a[3], b[3]); else if(l == 2) p[3] = f3(xx[3], yy[3], a[3], b[3]); else if(l == 3) p[3] = f4(xx[3], yy[3], a[3], b[3]); if(judge()) ans = min(ans, i + j + k + l); } if(ans == INF) printf("-1\n"); else printf("%d\n", ans); } return 0;}
0 0
- Codeforces 474 C. Captain Marmot
- CodeForces 474C - Captain Marmot
- 【CODEFORCES】 C. Captain Marmot
- codeforces 474c C. Captain Marmot
- codeforces 474C Captain Marmot dfs
- 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 704D Captain America
- BNU 0814 C The Captain's Squad
- Collection
- 并发程序模板(std::thread)
- 简单选择排序
- 响应式布局 BFC
- JAVA面向对象-----内部类的概述
- CodeForces 474C - Captain Marmot
- 理解Java垃圾回收
- gdb调试core时打印出当时变量的内容------有时可以主动制造core来看变量值
- Leetcode Word Search
- 欢迎使用CSDN-markdown编辑器
- Oracle11g数据库win8.1系统安装配置图文教程
- c++设计模式之桥接模式
- TTL & OS
- poj 1611 并查集