HDU 4998 Rotate
题意:
n次旋转 每次平面绕ai点旋转pi弧度 问 最后状态相当于初始状态绕A点旋转P弧度 A和P是多少
思路:
如果初始X点的最后状态为X‘点 则圆心一定在X和X'连线的垂直平分线上 那么仅仅要用在取一个点Y和Y' 相同做它的垂直平分线 两线交点即是圆心 然后用简单几何方法算出角度 最后注意要求最后状态由最初状态逆时针旋转得到 适当调整角度就可以
PS:
kuangbin巨巨的几何代码还是非常easy理解的 非常好用~ 谢谢~
代码:
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<cassert>
using namespace std;
typedef long long LL;
#define Q 401
#define N 51
#define M 200001
#define inf 2147483647
#define lowbit(x) (x&(-x)) const double eps = 1e-5;
const double PI = acos(-1.0); int sgn(double x) {
if (fabs(x) < eps)
return 0;
if (x < 0)
return -1;
else
return 1;
} struct Point {
double x, y;
Point() {
}
Point(double _x, double _y) {
x = _x;
y = _y;
}
Point operator +(const Point &b) const {
return Point(x + b.x, y + b.y);
}
Point operator -(const Point &b) const {
return Point(x - b.x, y - b.y);
}
//叉积
double operator ^(const Point &b) const {
return x * b.y - y * b.x;
}
//点积
double operator *(const Point &b) const {
return x * b.x + y * b.y;
}
//绕原点逆时针旋转角度B(弧度值)。后x,y的变化
void transXY(double B) {
double tx = x, ty = y;
x = tx * cos(B) - ty * sin(B);
y = tx * sin(B) + ty * cos(B);
}
} a1, a2, b1, b2, f1, f2, f3;
struct Line {
Point s, e;
Line() {
}
Line(Point _s, Point _e) {
s = _s;
e = _e;
}
//两直线相交求交点
//第一个值为0表示直线重合,为1表示平行,为2是相交
//仅仅有第一个值为2时。交点才有意义
pair<int, Point> operator &(const Line &b) const {
Point res = s;
if (sgn((s - e) ^ (b.s - b.e)) == 0) {
if (sgn((s - b.e) ^ (b.s - b.e)) == 0)
return make_pair(0, res); //重合
else
return make_pair(1, res); //平行
}
double t = ((s - b.s) ^ (b.s - b.e)) / ((s - e) ^ (b.s - b.e));
res.x += (e.x - s.x) * t;
res.y += (e.y - s.y) * t;
return make_pair(2, res);
}
} l1, l2; //两点间距离
double dist(Point a, Point b) {
return sqrt((a - b) * (a - b));
} int t, n; int main() {
int i;
double x, y, z;
scanf("%d", &t);
while (t--) {
a1 = f1 = Point(5e5, 3e5);
a2 = f2 = Point(1e5, 6e5);
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%lf%lf%lf", &x, &y, &z);
f3 = Point(x, y);
f1 = f1 - f3;
f2 = f2 - f3;
f1.transXY(z);
f2.transXY(z);
f1 = f1 + f3;
f2 = f2 + f3;
}
b1 = a1 + f1;
b1.x /= 2;
b1.y /= 2;
b2 = f1;
b2 = b2 - b1;
b2.transXY(PI / 2);
b2 = b2 + b1;
l1 = Line(b1, b2);
b1 = a2 + f2;
b1.x /= 2;
b1.y /= 2;
b2 = f2;
b2 = b2 - b1;
b2.transXY(PI / 2);
b2 = b2 + b1;
l2 = Line(b1, b2);
pair<int, Point> res = l1 & l2;
i = res.first;
f3 = res.second;
assert(i == 2);
printf("%f %f ", f3.x, f3.y);
f2 = f1 + a1;
f2.x /= 2;
f2.y /= 2;
x = atan(dist(f1, f2) / dist(f2, f3)) * 2;
y = PI + PI;
while (x > y)
x -= y;
while (x < 0)
x += y;
a1 = a1 - f3;
a1.transXY(x);
a1 = a1 + f3;
a1 = a1 - f1;
if (sgn(a1.x) || sgn(a1.y))
x = PI + PI - x;
printf("%f\n", x);
}
return 0;
}
HDU 4998 Rotate的更多相关文章
- HDU 4998 Rotate (计算几何)
HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...
- HDU 4998 Rotate --几何
题意:给n个点(x,y,p),从1~n,一次每次所有点绕着第 i 个点(原来的)逆时针转pi个弧度,问最后所有点的位置相当于绕哪个点旋转多少弧度,求出那点X和弧度P 解法:直接模拟旋转,每次计算新的坐 ...
- hdu 4998 Rotate 点的旋转 银牌题
Rotate Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU 4998 (点的旋转) Rotate
为了寻找等效旋转操作,我们任选两个点P0和Q0,分别绕这n个点旋转一定的角度后最终得到Pn和Qn 然后已知:P0和Pn共圆,Q0和Qn共圆.所以要找的等效旋转点就是这两个线段的垂直平分线交点O. 等效 ...
- hdu 4998
http://acm.hdu.edu.cn/showproblem.php?pid=4998 这道题,在比赛的时候看了很久,才明白题目的大意.都怪自己不好好学习英语.后来经过队友翻译才懂是什么意思. ...
- hdu 4998 矩阵表示旋转
http://acm.hdu.edu.cn/showproblem.php?pid=4998 http://blog.csdn.net/wcyoot/article/details/33310329 ...
- hdu第4场j.Let Sudoku Rotate
Problem J. Let Sudoku Rotate Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Su ...
- ACM学习历程—Rotate(HDU 2014 Anshan网赛)(几何)
Problem Description Noting is more interesting than rotation! Your little sister likes to rotate thi ...
- HDU - 6341 多校4 Let Sudoku Rotate(状压dfs)
Problem J. Let Sudoku Rotate Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K ...
随机推荐
- 中国本土管理咨询公司排名TOP50
中国本土管理咨询公司排名TOP50 1. 北京正略钧策管理顾问有限公司 2. 北京和君咨询公司 3. 北大纵横管理咨询公司 4. 远卓管理顾问公司 5. AMT管理咨询公司 6. 华夏基石管理咨询有限 ...
- Eclipse无提示的解决办法 和 内容辅助技巧
Eclipse无提示的解决办法 和 内容辅助技巧 一.若发现内容辅助失效没有提示 下面是解决办法,现贴出来与大家共享: 1.菜单window->Preferences->Jav ...
- hdu 4687 Boke and Tsukkomi
Dancing link twice. Find the maximum combination numbers in the first time. Enumerate each node, dan ...
- Swift - 浮点数转换成整数(四舍五入与直接截断)
1,直接截去小数部分转换成整数 使用强制转换会将浮点部分去除,把整数部分转换为整数. 1 var i = Int(23.50) //23 2,四舍五入转换成整数 lroundf是一个全局函数,作用是将 ...
- Error: 17053 LogWriter: Operating system error 21(The device is not ready.)
今天在Detach数据库的时候出现错误,运行DBCC CHECKDB从SQL Server error log中看到下面的信息: Error: 17053, Severity: 16, State: ...
- C++中的函数模板
我们在定义函数时,可以通过定义函数模板,来简化一些功能相同而数据类型不同的函数的定义和调用过程. C++中的函数模板 对于类的声明来说,也有同样的问题.有时,有两个或多个类,其功能是相同的,仅仅是数据 ...
- C++自删除
#pragma once class AutoRelease { public: AutoRelease(void){ m_count = 0; } virtual ~AutoRelease(void ...
- Apache+windows server2008 外网访问配置
之前在一个服务器上部署一个apache网站,在局域网内都可以访问,但是外网始终访问不了,经常多次谷歌,把解决方案总结出来. 下面就默认部署apache自带的网站.系统:windows server20 ...
- Go的String转码包
https://github.com/qiniu/iconv https://github.com/djimenez/iconv-go 这是与go不相干的转码包:https://github.com/ ...
- Scriptcase价格调整(五折销售)
芬兰诺基亚!芬兰诺基亚!最大手机公司倒闭了!王八蛋老板埃洛普,吃喝嫖赌欠下了3.5个亿,带着他的小姨子跑了!我们没有办法,拿着手机抵工资!原价都是一千多.两千多.三千多的手机,统统二百块!统统二百块! ...