题目链接: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. JSP include HTML出现乱码

    解决方法:在项目的web.xml中加入下面语句:<jsp-config>     <jsp-property-group>     <description>    ...

  2. hibernate 对象状态异常:object references an unsaved transient instance - save the transient instance before flushing

    我的问题出在,删除的对象对应的表中有一个外键,关联着另外一个表,可是另外一个表中没有数据,所以报了这个错误. 参考http://www.cnblogs.com/onlywujun/archive/20 ...

  3. Tuning “enq:TX – row lock contention” events

    enq是一种保护共享资源的锁定机制,一个排队机制 排它机制从一个事务的第一次改变直到rollback or commit 结束这个事务, TX等待mode是6,当一个session 在一个表的行级锁定 ...

  4. 中文翻译:pjsip教程(三)之ICE stream transport的使用

    1:pjsip教程(一)之PJNATH简介 2:pjsip教程(二)之ICE穿越打洞:Interactive Connectivity Establishment简介 3:pjsip教程(三)之ICE ...

  5. [Linux]ubuntu安装ftp服务器

     1: 安装vsftpd~$ sudo apt-get install vsftpd  or~$ yum install vsftpd温馨提示:ubuntu10.10自己装了,这步省略. 2: 配置v ...

  6. php基础知识【函数】(1)数组array

    一.排序 1.sort -- 从最低到最高排序,删除原有的键名,赋予新的键名[字母比数字高] 2.rsort -- 逆向排序(最高到最低),删除原有的键名,赋予新的键名[字母比数字高] 3.asort ...

  7. C#获取硬盘空间信息

    /// <summary> /// 获取指定驱动器的空间总大小(单位为B) /// </summary> /// <param name="str_HardDi ...

  8. ASP.NET MVC轻教程 Step By Step 4——Model、View和Controller

    ASP.NET MVC中的Model(数据模型)主要包括定义数据结构.数据库读写.数据验证等等和对象处理相关的工作. 在解决方案资源管理器中找到Model文件夹,点击右键,添加一个新类,名为“Mess ...

  9. ligerUI路径问题

    ligerUI放mv的Content目录下,路径为固定的并且必须引进一下文件 <link href="~/Content/Ligerui/Source/lib/ligerUI/skin ...

  10. 第三方:GDataXMLNode:xml解析库--备用

    一.GDataXMLNode说明   GDataXMLNode是Google提供的用于XML数据处理的类集.该类集对libxml2--DOM处理方式进行了封装,能对较小或中等的xml文档进行读写操作且 ...