http://acm.hdu.edu.cn/showproblem.php?pid=4998

这道题,在比赛的时候看了很久,才明白题目的大意。都怪自己不好好学习英语。后来经过队友翻译才懂是什么意思。

题目大意:二维平面内的物品,把它们绕给定的n个点,逆时针旋转。 现在求通过一个A点,逆时针旋转角度P就能完成这个操作。

问:这个点A的坐标,P的角度。

解题思路:随意找个点t1,绕着n个点旋转得到t2。点A一定在线段t1t2的垂直平分线上。再找一点t3,绕n个点旋转得到t4。

线段t1t2的垂直平分线和线段t3t4的垂直平分线相交一点,这点就是A点。证明过程就不写了,可以画图看看。

旋转的角度是向量At1和向量At2的夹角Θ,或是2∏-Θ

 #include<cstdio>
#include<cmath>
#include<iostream>
using namespace std; struct Point{
double x, y; Point(double x = , double y = ): x(x), y(y){}
}; typedef Point Vector; const double eps = 1e-; int dcmp(double x){
if(fabs(x) < eps)
return ;
return x < ? - : ;
} bool operator == (Point A, Point B){
return dcmp(A.x - B.x) == && dcmp(A.y - B.y) == ;
} Vector operator + (Vector A, Vector B){
return Vector(A.x + B.x, A.y + B.y);
} Vector operator - (Vector A, Vector B){
return Vector(A.x - B.x, A.y - B.y);
} Vector operator * (Vector A, double p){
return Vector(A.x * p, A.y * p);
} Vector operator / (Vector A, double p){
return Vector(A.x / p, A.y / p);
} double dot(Vector A, Vector B){//点乘
return A.x * B.x + A.y * B.y;
} double length(Vector A){//向量的模
return sqrt(dot(A, A));
} double angle(Vector A, Vector B){//两个向量的夹角
return acos(dot(A, B) / length(A) / length(B));
} Vector rotate(Vector A, double rad){//点A绕原点旋转角度为rad
return Vector(A.x * cos(rad) - A.y * sin(rad), A.x * sin(rad) + A.y * cos(rad));
} Vector normal(Vector A){//向量的法向量
double L = length(A);
return Vector(-A.y / L, A.x / L);
} double cross(Vector A, Vector B){//叉乘
return A.x * B.y - A.y * B.x;
} int n;
Point p[];
double ra[]; void input(){
cin>> n;
for(int i = ; i < n; ++i){
cin>> p[i].x>> p[i].y>> ra[i];
if(dcmp(ra[i] - * acos(-1.0)) == || dcmp(ra[i]) == ){
//当输入的弧度为0或者2π时,都是没用的
ra[i] = ;
n--;
i--;
}
}
} Vector rotate_point(Vector A){//将A点绕n个点旋转
for(int i = ; i < n; ++i){
A = p[i] + rotate(A - p[i], ra[i]);
}
return A;
} Vector mid_point(Point A, Point B){//求两点之间的中点
return Vector((A.x + B.x) / , (A.y + B.y) / );
} Point get_line_intersection(Point P, Vector v, Point Q, Vector w){//两直线求交点,《算法入门经典训练之南》几何
Vector u = P - Q;
double t = cross(w, u) / cross(v, w);
return P + v * t;
} void solve(){
Point t1[], t2[], mid[], vec[];
t1[].x = -;
t1[].y = -;
t1[].x = -;
t1[].y = -;
for(int i = ; i < ; ++i){
t2[i] = rotate_point(t1[i]);
mid[i] = mid_point(t1[i], t2[i]);
vec[i] = normal(t1[i] - t2[i]);
}
Point ans = get_line_intersection(mid[], vec[], mid[], vec[]);//答案点A
double ansp = angle(t1[] - ans, t2[] - ans);//旋转角度P if(cross(t1[] - ans, t2[] - ans) < ){//判断是ansp 还是2π - ansp
ansp = * acos(-1.0) - ansp;
} if(dcmp(ans.x) == ){//加入答案是-1e-11,如果直接输出就会是-0.0000000000
ans.x = ;
}
if(dcmp(ans.y) == ){
ans.y = ;
} printf("%.10lf %.10lf %.10lf\n", ans.x, ans.y, ansp);
} int main(){
//freopen("data.in", "r", stdin);
//freopen("data.out", "w", stdout);
int t;
cin>> t;
while(t--){
input();
solve();
}
return ;
}

AC代码

hdu 4998的更多相关文章

  1. HDU 4998 Rotate (计算几何)

    HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...

  2. hdu 4998 矩阵表示旋转

    http://acm.hdu.edu.cn/showproblem.php?pid=4998 http://blog.csdn.net/wcyoot/article/details/33310329 ...

  3. HDU 4998 Rotate --几何

    题意:给n个点(x,y,p),从1~n,一次每次所有点绕着第 i 个点(原来的)逆时针转pi个弧度,问最后所有点的位置相当于绕哪个点旋转多少弧度,求出那点X和弧度P 解法:直接模拟旋转,每次计算新的坐 ...

  4. HDU 4998 (点的旋转) Rotate

    为了寻找等效旋转操作,我们任选两个点P0和Q0,分别绕这n个点旋转一定的角度后最终得到Pn和Qn 然后已知:P0和Pn共圆,Q0和Qn共圆.所以要找的等效旋转点就是这两个线段的垂直平分线交点O. 等效 ...

  5. HDU 4998 Rotate

    题意: n次旋转  每次平面绕ai点旋转pi弧度  问  最后状态相当于初始状态绕A点旋转P弧度  A和P是多少 思路: 如果初始X点的最后状态为X'点  则圆心一定在X和X'连线的垂直平分线上  那 ...

  6. hdu 4998 Rotate 点的旋转 银牌题

    Rotate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. 在Delphi中如何动态创建dbf数据库(二)?

    unit Form_ToChangCSVforDBFU; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics ...

  2. VS附加到进程调试的方法及应用场景

    应用场景:.Net做网站时,代码量很大的时候,每次调试一个网页都编译整个网站是不显示的,而且有时候整个网站是存在错误的,通不过编译.这时你又要调试某部分网页,就可以通过附加到进程调试.方法如下: (1 ...

  3. nginx博客系统(内含nginx图片缩略图处理代码,不错)

    一直以来都在Qzone.CSDN等上面写博客,偶尔有些想法就在Paas平台上搭建服务,新浪和曾经的google上都用过其appengine.可是在别人的平台上写东西,总归有些不方便,有受制于人的感觉. ...

  4. php--validate表单验证

    validate表单验证扩展规则 添加自定义检验(验证class) 获取html加入 class <input id="D_NUMBER" name="D_NUMB ...

  5. xdebug和xhprof

    在安装时出现不是:1% 不是有效的win32 应用程序原因可能是是下载了64位的.dll扩展与当前的php不兼容

  6. I Count Two Three---hdu5878(打表+二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题意:找到第一个>=n的数x, 满足 x = 2a3b5c7d:n<=1e9; 打表 ...

  7. js保留n位小数

    1.功能:将浮点数四舍五入,取小数点后2位 function toDecimal(num) { var f = parseFloat(num); if (isNaN(f)) { return; } f ...

  8. 第二条 一个类如果有多个参数,考虑用Builder构造者模式

    1. @Data public class Student { //体检用 private String name; private int age; private int height; priv ...

  9. 使用 Redis 实现分布式系统轻量级协调技术

    http://www.ibm.com/developerworks/cn/opensource/os-cn-redis-coordinate/index.html 在分布式系统中,各个进程(本文使用进 ...

  10. Task+http请求

    Task+http请求  这个算是一个简单的事例吧