120. Archipelago

time limit per test: 0.25 sec. 

memory limit per test: 4096 KB

Archipelago Ber-Islands consists of N islands that are vertices of equiangular and equilateral N-gon. Islands are clockwise numerated. Coordinates of island N1 are (x1, y1),
and island N2 – (x2, y2). Your task is to find coordinates of all N islands.

Input

In the first line of input there are N, N1 and N2 (3£ N£ 150, 1£ N1,N2£N,
N1¹N2
separated by spaces. On the next two lines of input there are coordinates of island N1 and N2 (one pair per line) with accuracy 4digits
after decimal point. Each coordinate is more than -2000000 and less than 2000000.

Output

Write N lines with coordinates for every island. Write coordinates in order of island numeration. Write answer with 6 digits after decimal point.

Sample Input

4 1 3
1.0000 0.0000
1.0000 2.0000

Sample Output

1.000000 0.000000
0.000000 1.000000
1.000000 2.000000
2.000000 1.000000
 
题意:给你正N边形上两个点,按顺时针给出。让你按顺时针输出这N个点

思路:用向量N1N2的中垂线 和 向量N1N2旋转(n2-n1)*PI/n的交点就可以求出圆心。求出圆心后用向量n1O旋转N遍就可以。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#define REP(_,a,b) for(int _ = (a); _ <= (b); _++)
using namespace std;
const double eps = 1e-10;
const int maxn = 160;
const double PI = acos(-1.0);
double ang,rad;
int n,n1,n2;
struct Point{
double x,y;
Point(double x=0.0,double y = 0.0):x(x),y(y){}
}P[maxn];
typedef Point Vector; struct Line {
Point P;
Vector v;
double ang;
Line(){}
Line(Point P,Vector v):P(P),v(v){
ang = atan2(v.y,v.x);
}
bool operator <(const Line&L) const{
return ang < L.ang;
}
};
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);
}
bool operator < (const Point &a,const Point &b){
return a.x < b.x || (a.x==a.y && a.y < b.y);
}
int dcmp(double x){
if(fabs(x) < eps) return 0;
else return x < 0? -1:1;
}
bool operator == (const Point &a,const Point &b){
return dcmp(a.x-b.x)==0&& dcmp(a.y-b.y)==0;
}
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));}
double Cross(Vector A,Vector B) {return A.x*B.y-A.y*B.x;}
Vector Rotate(Vector A,double 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);
}
Point GetIntersection(Line a,Line b){
Vector u = a.P-b.P;
double t = Cross(b.v,u) / Cross(a.v,b.v);
return a.P+a.v*t;
}
int main(){
while(~scanf("%d%d%d",&n,&n1,&n2)){
ang = (n2-n1)*PI/n;
rad = 2*PI/n;
scanf("%lf%lf%lf%lf",&P[n1].x,&P[n1].y,&P[n2].x,&P[n2].y);
Line a = Line((P[n1]+P[n2])/2,Normal(P[n2]-P[n1]));
Line b = Line(P[n1],Rotate(Normal(P[n2]-P[n1]),ang));
Point o = GetIntersection(a,b);
Vector t = P[n1]-o;
int d = n1+1,cnt = 1;
while(d != n1){
P[d] = o+Rotate(t,-cnt*rad);
d = d%n + 1;
cnt++;
}
REP(i,1,n) {
printf("%.6lf %.6lf\n",P[i].x,P[i].y);
}
}
return 0;
}
 
题意:给你正N边形上两个点。按顺时针给出,让你按顺时针输出这N个点

思路:用向量N1N2的中垂线 和 向量N1N2旋转(n2-n1)*PI/n的交点就可以求出圆心。求出圆心后用向量n1O旋转N遍就可以。

SGU 120 Archipelago (简单几何)的更多相关文章

  1. Python下opencv使用笔记(二)(简单几何图像绘制)

    简单几何图像一般包含点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义. 图像的一个像素点有1或者3个值.对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值.他们表现出 ...

  2. Codeforces 935 简单几何求圆心 DP快速幂求与逆元

    A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...

  3. Archipelago - SGU 120(计算几何向量旋转)

    题目大意:有一个正N边形,然后给出两个点,求出剩余的点的坐标. 分析:向量旋转可以求出坐标,顺时针旋转时候,x = x'*cos(a) + y'*sin(a), y=-x'*sin(a) + y'*c ...

  4. 简单几何(线段相交) POJ 2653 Pick-up sticks

    题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...

  5. osg for android (一) 简单几何物体的加载与显示

    1. 首先需要一个OSG for android的环境. (1).NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考 Android NDK开发篇(一) ...

  6. HDU 6206 青岛网络赛1001 高精度 简单几何

    给出的数据1e12规模,常规判点是否在圆范围内肯定要用到半径,求得过程中无法避免溢出,因此用JAVA自带的浮点大数运算,和个ZZ一样比赛中eclipse出现问题,而且太久没写JAVA语法都不清楚变量忘 ...

  7. CodeForces 703C Chris and Road (简单几何)

    题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...

  8. Jack Straws POJ - 1127 (简单几何计算 + 并查集)

    In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table ...

  9. codeforces 394E Lightbulb for Minister 简单几何

    题目链接:点我点我 题意:给定n个点. 以下n行给出这n个点坐标. 给定m个点,以下m行给出这m个点坐标. 这m个点是一个凸包,顺时针给出的. 问:在凸包上随意找一个点(x, y) 使得这个点距离n个 ...

随机推荐

  1. HDUOJ-Counting Triangles

    Counting Triangles Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  2. Python学习笔记011——内置函数exec()

    1 描述 把一个字符串当成语句执行 exec()  执行储存在字符串或文件中的 Python 语句,相比于  eval() , exec() 可以执行更复杂的 Python 代码. exec函数和ev ...

  3. WebADI_WebADI工作日志设定(案例)

    20150707 Created By BaoXinjian

  4. C# GridView 给某行或某列绑定点击事件和鼠标事件

    protected void GridViewEx1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType = ...

  5. Spark Core Runtime分析: DAGScheduler, TaskScheduler, SchedulerBackend

    Spark Runtime里的主要层次分析,梳理Runtime组件和运行流程, DAGScheduler Job=多个stage,Stage=多个同种task, Task分为ShuffleMapTas ...

  6. STM32 SPI接口的NSS引脚

    SPI_NSS 设置 NSS 信号由硬件( NSS 管脚)还是软件控制,这里我们一般通过软件控制 NSS ,而不是硬件自动控制,所以选择 SPI_NSS_Soft 选择了软件NSS之后,引脚NSS就可 ...

  7. PixelLink

    简介 论文题目:PixelLink: Detecting Scene Text via Instance Segmentation 论文地址:https://arxiv.org/abs/1801.01 ...

  8. mysql InnoDB 的行锁

    表的引擎类型必须为InnoDB才可以进行此操作. 相关链接:http://www.cnblogs.com/CyLee/p/5579672.html 共享锁:单独运行前两句,然后新建一个会话使用第三句. ...

  9. Linux-Ubuntu操作记录

    ubuntu 基本命令 1.帮助man      --help简单的帮助  如:man tar 或者tar --help      help command 较详细的帮助      man comma ...

  10. 怎么从docker中copy文件到 本机

    怎么从docker中copy文件到 本机 docker cp <containerId>:/file/path/within/container /host/path/target