CodeForces 474C Captain Marmot (数学,旋转,暴力)
题意:给定 4n * 2 个坐标,分成 n组,让你判断,点绕点的最少次数使得四个点是一个正方形的顶点。
析:那么就一个一个的判断,n 很小,不会超时,四个点分别从不转然后转一次,转两次。。。转四次,就这样算下去,那么如何判断是不是正方形呢?这样判定就行,把每个边都求出来,然后判定,
这里肯定有四个边是一样,另外两个是一样的,而且还不是0,因为可能重合,关键是旋转后怎么算呢?有两个公式,假设点(x, y)绕点(a, b)转 x 角度,那么旋转后的坐标为 (xx, yy),应该是,
xx = (x - a) cos x - (y-b) sin x + a; yy = (x-a) sin x + (y-b) cos x + b;这就是转任意角度的结果。那么剩下的就很简单了,注意,如果用int 可能会溢出,用double注意精度。
代码如下:
#include <bits/stdc++.h> using namespace std;
typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 400 + 5;
int a[maxn], b[maxn], x[maxn], y[maxn];
int xx[5], yy[5]; void rot(int t, int *s){//旋转
for(int i = 0; i < 4; ++i){//四个点旋转
xx[t+i] = x[t+i], yy[t+i] = y[t+i];
for(int j = 0; j < s[i]; ++j){//第 i 个数旋转
int xxx = xx[t+i];
xx[t+i] = a[t+i] - yy[t+i] + b[t+i];
yy[t+i] = xxx - a[t+i] + b[t+i];
}
}
} bool judge(int t, int *x, int *y){
vector<LL> v;
for(int i = 0; i < 4; ++i)
for(int j = 0 ; j < 4; ++j){
if(i == j) continue;
LL xx = ((LL)x[t+i]-(LL)x[t+j]) * ((LL)x[t+i]-(LL)x[t+j]) + ((LL)y[t+i]-(LL)y[t+j]) * ((LL)y[t+i]-(LL)y[t+j]);//计算边长
v.push_back(xx);//记录边长
} sort(v.begin(), v.end());//排序 int tt = 0, ii = 0;//计算数量
for(int i = 0 ; i < 12; ++i){
if(v[i] == v[0] && v[i]) ++tt;
else if(v[i] == v[11] && v[i]) ++ii;
}
if(tt == 8 && ii == 4) return true;
return false;
} int solve(int t){
int ans = 1000;
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(ans < i + j + k +l) continue;//如果小于才循环
int s[] = {i, j, k, l};
rot(t, s);
if(judge(t, xx, yy)) ans = i + j + k + l;
} return ans == 1000 ? -1 : ans;
} int main(){
int n;
cin >> n;
for(int i = 1; i <= 4*n; ++i) scanf("%d %d %d %d", &x[i], &y[i], &a[i], &b[i]); for(int i = 1; i < 4*n; i += 4)
cout << solve(i) << endl; return 0;
}
CodeForces 474C Captain Marmot (数学,旋转,暴力)的更多相关文章
- Codeforces 474C Captain Marmot 给定4个点和各自旋转中心 问旋转成正方形的次数
题目链接:点击打开链接 题意: 给定T表示case数 以下4行是一个case 每行2个点,u v 每次u能够绕着v逆时针转90° 问最少操作多少次使得4个u构成一个正方形. 思路: 枚举判可行 #in ...
- Codeforces 474 C. Captain Marmot
4*4*4*4暴力+点的旋转+推断正方型 C. Captain Marmot time limit per test 1 second memory limit per test 256 megaby ...
- C. Captain Marmot (Codeforces Round #271)
C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- 【CODEFORCES】 C. Captain Marmot
C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces 271 Div 2 C. Captain Marmot
题目链接:http://codeforces.com/contest/474/problem/C 解题报告:给一个n,然后输入4*n个平面坐标系上的点,每四个点是一组,每个点有一个中心,这四个点可以分 ...
- codeforces 687B - Remainders Game 数学相关(互质中国剩余定理)
题意:给你x%ci=bi(x未知),是否能确定x%k的值(k已知) ——数学相关知识: 首先:我们知道一些事情,对于k,假设有ci%k==0,那么一定能确定x%k的值,比如k=5和ci=20,知道x% ...
- Codeforces Gym 100513M M. Variable Shadowing 暴力
M. Variable Shadowing Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/ ...
- Codeforces Gym 100513G G. FacePalm Accounting 暴力
G. FacePalm Accounting Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513 ...
- Codeforces Gym 100002 C "Cricket Field" 暴力
"Cricket Field" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/1000 ...
随机推荐
- PHP for和foreach的区别
首先,我们先准备两个用于遍历的数组: $arr1=array(1=>'a', 3=>22, 5=>'b', 4=>'c', 8=>'d'); $arr2=array('a ...
- 安卓权限处理 PermissionDog
PermissionDog 简介 权限狗 权限申请 最近在一家公司实习,项目中需要用到适配安卓6.0以上的系统,我本来是想用其他人已经写好的权限申请框架来实现的,但是发现跟我的需求有点小区别,所以就自 ...
- 3.docker学习之docker与虚拟化
虚拟化技术是一个总称,是一系列实现虚拟技术的统称.从广义上来说,虚拟化技术包括了虚拟机技术和容器技术, 所谓虚拟化技术最大的特点就是将一个真实的机器进行虚拟地分割,然后分割出来的部分可以独立使用 ...
- 好记性不如烂笔头-Mysql查找如何判断字段是否包含某个字符串
好记性不如烂笔头-Mysql查找如何判断字段是否包含某个字符串 利用mysql 字符串函数 find_in_set(); SELECT * FROM users WHERE find_in_set(' ...
- LeetCode题解 #8 String to Integer (atoi)
又是一道恶心的简单题. 一开始没想到这么多情况的,幸好LeetCode是个很人性化的oj,能让你知道你在哪个case上错了,否则一辈子都过不了. 考虑不周到只能一个个补了. 列举一下恶心的case / ...
- 记录两个python的小问题
使用python也前前后后也一个月的样子,记录两个一直没注意的问题. 1. 元组的使用(拼接字符串) 直接看下面的代码: >>> kel = 'some','strings' > ...
- RocketMQ初探(二)之RocketMQ3.26版本搭建(含简单Demo测试案例)
作为一名程序猿,要敢于直面各种现实,脾气要好,心态要棒,纵使Bug虐我千百遍,我待它如初恋,方法也有千万种,一条路不行,换条路走走,方向对了,只要前行,总会上了罗马的道. Apache4.x最新版本既 ...
- 【摘录】UNITY优化-有关骨骼数量的上限问题
1.顶点性能一般来说,如果您想在iPhone 3GS或更新的设备上每帧渲染不超过40,000可见点,那么对于一些配备 MBX GPU的旧设备(比如,原始的 iPhone,如 iPhone 3g和 iP ...
- java.lang.IllegalStateException: getOutputStream() has already been called for this response解决方案
异常产生原因:web容器生成的servlet代码中有out.write(""),这个和JSP中调用的response.getOutputStream()产生冲突.即Servlet规 ...
- AspectJ的aop编程--切入点表达式