题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1046

参考博客:http://hi.baidu.com/cloudygoose/item/21fee021a5db348d9d63d17b

参考资料(向量的旋转):http://www.cnblogs.com/woodfish1988/archive/2007/09/10/888439.html

题目大意:就是已知n个点,n个角。点Mi可以与多边形Ai和Ai+1构成等腰三角形,顶角为ang[i].  现在要你求出这个多边形的n的顶点。

算法思路:刚开始想几何性质,怎么也想不出来一个好的思路。没办法,网搜才知道要用解方程的方法。蛋疼的是没写过,别人的代码有是懂非懂的。慢慢琢磨才发现其实现方程求解的思路。先看看那个参考博客的思路吧。

我只是大致翻译一下他的思想: 我们知道: Ai+1 = Rotate(Ai-Mi,ang[i]) + Mi;  (画画图就知道)                整理下就是:Ai+1 = P1' * Ai + P2';

而由A1递推来 :   Ai = P1 * A1 + P2;        我们编程时要不断更新这个P1和P2;

具体看代码:

代码:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std; const double eps = 1e-;
const double PI = acos(-1.0);
const double INF = 1000000000000000.000; struct Point{
double x,y;
Point(double x=, double y=) : x(x),y(y){ } //构造函数
};
typedef Point Vector; struct Circle{
Point c;
double r;
Circle() {}
Circle(Point c,double r): c(c),r(r) {}
};
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 * (double p,Vector A){return Vector(A.x*p,A.y*p);}
Vector operator / (Vector A , double p){return Vector(A.x/p,A.y/p);} bool operator < (const Point& a,const Point& b){
return a.x < b.x ||( a.x == b.x && a.y < b.y);
} int dcmp(double x){
if(fabs(x) < eps) return ;
else return x < ? - : ;
}
bool operator == (const Point& a, const Point& b){
return dcmp(a.x - b.x) == && dcmp(a.y - b.y) == ;
} ///向量(x,y)的极角用atan2(y,x);
inline double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; }
inline double Length(Vector A) { return sqrt(Dot(A,A)); }
inline double Angle(Vector A, Vector B) { return acos(Dot(A,B) / Length(A) / Length(B)); }
double Cross(Vector A, Vector B) { return A.x*B.y - A.y * B.x; } Vector vecunit(Vector v){ return v / Length(v);} //单位向量
double torad(double deg) { return deg/ * PI; }
Vector Rotate(Vector A, double rad) { return Vector(A.x*cos(rad)-A.y*sin(rad),A.x*sin(rad)+A.y*cos(rad)); } /*************************************分 割 线*****************************************/ int main()
{
//freopen("E:\\acm\\input.txt","r",stdin); const int maxn = ;
Point M[maxn],P1,P2; double ang[maxn];
int n; cin>>n;
for(int i=; i<=n; i++)
{
scanf("%lf %lf",&M[i].x,&M[i].y);
}
for(int i=; i<=n; i++)
{
scanf("%lf",&ang[i]);
ang[i] = torad(ang[i]);
} P1 = Point(,);
P2 = Point(,); for(int i=; i<=n; i++)
{
P1 = Rotate(P1,ang[i]);
P2 = Rotate(P2,ang[i]);
P2 = P2 + M[i] - Rotate(M[i],ang[i]);
} P1.x -= ;
P2.x = -P2.x;
P2.y = -P2.y; Point ans; //求ans时,把P1,P2看成复平面中的点,即P1表示为P1.x+P2.y*i; 然后ans = P2/P1,用虚数就可求出。
ans.x = (P1.x*P2.x+P1.y*P2.y)/(P1.x*P1.x+P1.y*P1.y);
ans.y = (-P1.y*P2.x+P1.x*P2.y)/(P1.x*P1.x+P1.y*P1.y); for(int i=; i<=n; i++)
{
printf("%.2lf %.2lf\n",ans.x,ans.y);
ans = M[i] + Rotate(ans-M[i],ang[i]);
}
}

Ural 1046 Geometrical Dreams(解方程+计算几何)的更多相关文章

  1. vijos P1915 解方程 加强版

    背景 B酱为NOIP 2014出了一道有趣的题目, 可是在NOIP现场, B酱发现数据规模给错了, 他很伤心, 哭得很可怜..... 为了安慰可怜的B酱, vijos刻意挂出来了真实的题目! 描述 已 ...

  2. HDU 4793 Collision --解方程

    题意: 给一个圆盘,圆心为(0,0),半径为Rm, 然后给一个圆形区域,圆心同此圆盘,半径为R(R>Rm),一枚硬币(圆形),圆心为(x,y),半径为r,一定在圆形区域外面,速度向量为(vx,v ...

  3. codevs3732==洛谷 解方程P2312 解方程

    P2312 解方程 195通过 1.6K提交 题目提供者该用户不存在 标签数论(数学相关)高精2014NOIp提高组 难度提高+/省选- 提交该题 讨论 题解 记录   题目描述 已知多项式方程: a ...

  4. [NOIP2014]解方程

    3732 解方程  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解       题目描述 Description 输入描述 Input Descrip ...

  5. bzoj 3751: [NOIP2014]解方程 同余系枚举

    3.解方程(equation.cpp/c/pas)[问题描述]已知多项式方程:a ! + a ! x + a ! x ! + ⋯ + a ! x ! = 0求这个方程在[1, m]内的整数解(n 和 ...

  6. 2017广东工业大学程序设计竞赛决赛 题解&源码(A,数学解方程,B,贪心博弈,C,递归,D,水,E,贪心,面试题,F,贪心,枚举,LCA,G,dp,记忆化搜索,H,思维题)

    心得: 这比赛真的是不要不要的,pending了一下午,也不知道对错,直接做过去就是了,也没有管太多! Problem A: 两只老虎 Description 来,我们先来放松下,听听儿歌,一起“唱” ...

  7. 5.5Python数据处理篇之Sympy系列(五)---解方程

    目录 目录 前言 (一)求解多元一次方程-solve() 1.说明: 2.源代码: 3.输出: (二)解线性方程组-linsolve() 1.说明: 2.源代码: 3.输出: (三)解非线性方程组-n ...

  8. python 解方程

    [怪毛匠子=整理] SymPy 库 安装 sudo pip install sympy x = Symbol('x') 解方程 solve([2 * x - y - 3, 3 * x + y - 7] ...

  9. python 解方程 和 python 距离公式实现

    解方程参考:https://zhuanlan.zhihu.com/p/24893371 缺点太慢,最后还是自己算了 距离公式参考:https://www.cnblogs.com/denny402/p/ ...

随机推荐

  1. OC多文件开发介绍

    OC多文件开发介绍: 1.为什么要使用多文件? 在工作中,通常把不同的类放到不同的文件中,每个类的声明和实现分开,声明写在.h头文件中,实现写在相应的.m文件中去,类名是什么,文件名的前缀就是什么.假 ...

  2. PL/SQL常见设置--Kevin的专栏

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  3. GridView 编辑、删除 、分页

    类似代码都差不多,记录一下,便于以后查看使用. 前台页面: <asp:GridView ID="gdvList" runat="server" AutoG ...

  4. 手机定位原理 - GPS/GLONASS/北斗 + WIFI + 基站

    卫星定位系统 - GPS/GLONASS/北斗: 关于GPS.GLONASS.北斗.伽利略系统的科普请自行谷歌. GPS是使用最广泛的全球定位网络,几乎是所有智能手机的标配.进几年,俄罗斯的GLONA ...

  5. java.net.ServerSocket和java.net.Socket

    个人博客地址:http://www.cnblogs.com/wdfwolf3/ java.net.ServerSocket 1.构造函数 a.ServerSocket() 创建一个无连接的server ...

  6. 【BZOJ3527】【FFT】力

    [问题描述]给出n个数qi,给出Fj的定义如下:令Ei=Fi/qi.试求Ei.[输入格式]输入文件force.in包含一个整数n,接下来n行每行输入一个数,第i行表示qi.[输出格式]输出文件forc ...

  7. OC语言-03NSString

    /* 1. @"kite" 这是一个OC字符串,OC的字符串也是一个对象, 由NSString类(继承于NSObject) 创建 2. 输出时使用 %@ 3. 对象方法 [对象名 ...

  8. matlab读取指定路径下的图像

    利用matlab读取指定路径下的图像 %% 读入指定路径imgFolder下的图像imgName imgFolder = 'F:\博\快盘\图像+数据\images\文章实验图'; %指定路径 img ...

  9. 3d max export for unity3d

    3d max export for unity3d @by 广州小龙 1.单位问题 建模的时候,设置unity的Units Setup的单位是Meters,导出FBX文件的时候,单位为厘米(Centi ...

  10. Unity3D 命令行参数

    Unity3D 命令行参数 @by 广州小龙                                              unity ios开发群:63438968 Typically, ...