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 ...
随机推荐
- Ajax显示隐藏
$(function(){ $('#search').click(function(){ if($(".search_div").is(":visible")) ...
- Windbg查看w3wp进程占用的内存及.NET内存泄露,死锁分析
https://www.cnblogs.com/startpoint/p/4194052.html https://www.cnblogs.com/lyl6796910/p/7613664.html ...
- yum问题的解决办法
关于使用yum“The program package-cleanup is...”的解决办法 在使用yum 时总是有提示信息: The program package-cleanup is f ...
- 全面了解POI操作Microsoft Office(Word、Excel、PowerPoint)
POI 与 Microsoft Office 1. POI 简介 POI 是 Apache 下的 Jakata 项目的一个子项目,主要用于提供 java 操作 Microsoft Office 办公套 ...
- python:while 语句的使用方法
while语句: count = 0 while True: print(count) count += 1 if count == 10: break 实例: 计算n!,若:n = 5:则:n! = ...
- UNITY 画布的粗浅理解
画布:当画布是screen-space overlay时,这个好理解,画布可以控制如分辨率,层次等.但当画布是 world-space时,这个严格来说就不算是一个画布了,屏幕空间或相机空间的画布是先绘 ...
- 网卡流量监控脚本 ( Shell )
#!/bin/bash # Traffic Monitor # author: Xiao Guaishou get_traffic_info(){ recv=`cat /proc/net/dev | ...
- C++ Assert()函数
assert宏的原型定义在<assert.h>中,其作用是如果它的条件返回错误,则终止程序执行,原型定义: #include <assert.h> void assert( i ...
- iOS学习之WebView的使用
1.使用UIWebView加载网页 运行XCode 4.3,新建一个Single View Application,命名为WebViewDemo. 2.加载WebView 在ViewControlle ...
- filter入门
TestFilter.java package com.cdsxt.filter; import java.io.IOException; import javax.servlet.Filter;im ...