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¹N2separated 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 思路:首先旋转N1N2一定角度到圆心方向利用三角形求出圆心O,然后旋转oN1得到其他点
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn=150;
const double eps=1e-12;
const double pie=acos(-1);
double xo,yo;
double x[maxn],y[maxn];
int n,n1,n2;
typedef pair<double,double> P;
P rot(double x,double y,double angle){
P p1;
p1.first=y*sin(angle)+x*cos(angle);
p1.second=y*cos(angle)-x*sin(angle);
return p1;
}
int main(){
scanf("%d%d%d",&n,&n1,&n2);n1--;n2--;
scanf("%lf%lf%lf%lf",x+n1,y+n1,x+n2,y+n2);
if(n1>n2)swap(n1,n2);
P p1=P(x[n2]-x[n1],y[n2]-y[n1]);
int gap=n2-n1;
double angle=pie/n*gap;
double angle2=pie/2-angle;if(angle<eps)angle+=pie;//取夹角不可能钝角或<0
p1=rot(p1.first,p1.second,angle2);
p1.first=-p1.first/2/cos(angle2);
p1.second=-p1.second/2/cos(angle2);
xo=-p1.first+x[n1],yo=-p1.second+y[n1];
for(int i=(n1+1)%n;i!=n1;i=(i+1)%n){
p1=rot(p1.first,p1.second,2*pie/n);
x[i]=p1.first+xo;
y[i]=p1.second+yo;
}
for(int i=0;i<n;i++){
printf("%.6f %.6f\n",x[i],y[i]);
}
return 0;
}

  

快速切题 sgu120. Archipelago 计算几何的更多相关文章

  1. 快速切题sgu127. Telephone directory

    127. Telephone directory time limit per test: 0.25 sec. memory limit per test: 4096 KB CIA has decid ...

  2. 快速切题sgu126. Boxes

    126. Boxes time limit per test: 0.25 sec. memory limit per test: 4096 KB There are two boxes. There ...

  3. 快速切题 sgu123. The sum

    123. The sum time limit per test: 0.25 sec. memory limit per test: 4096 KB The Fibonacci sequence of ...

  4. 快速切题 sgu119. Magic Pairs

    119. Magic Pairs time limit per test: 0.5 sec. memory limit per test: 4096 KB “Prove that for any in ...

  5. 快速切题 sgu118. Digital Root 秦九韶公式

    118. Digital Root time limit per test: 0.25 sec. memory limit per test: 4096 KB Let f(n) be a sum of ...

  6. 快速切题 sgu117. Counting 分解质因数

    117. Counting time limit per test: 0.25 sec. memory limit per test: 4096 KB Find amount of numbers f ...

  7. 快速切题 sgu116. Index of super-prime bfs+树思想

    116. Index of super-prime time limit per test: 0.25 sec. memory limit per test: 4096 KB Let P1, P2, ...

  8. 快速切题 sgu115. Calendar 模拟 难度:0

    115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...

  9. 快速切题 sgu113 Nearly prime numbers 难度:0

    113. Nearly prime numbers time limit per test: 0.25 sec. memory limit per test: 4096 KB Nearly prime ...

随机推荐

  1. C++ 项目中直接使用JsonCpp源码文件

    之前在网上看到使用JsonCpp都是以库的形式使用(编译源码为静态库或者动态库),这样引用很方便,但有时候报错调试看不到错误的地方,所以就想直接把源文件添加到项目中,方便调试 这是用到源码文件: 创建 ...

  2. C#中基于流的XML文件操作笔记

    System.Xml.XmlReader和System.Xml.XmlWriters是两个抽象类,XmlReader提供了对于XML数据的快速,非缓存,只进模式的读取器,XmlWriter表示一个编写 ...

  3. POJ 1830 开关问题(高斯消元)题解

    思路:乍一看好像和线性代数没什么关系.我们用一个数组B表示第i个位置的灯变了没有,然后假设我用u[i] = 1表示动开关i,mp[i][j] = 1表示动了i之后j也会跟着动,那么第i个开关的最终状态 ...

  4. spring-boot-devtools 实现热部署

    1.devtools spring为开发者提供了一个名为spring-boot-devtools的模块来使Spring Boot应用支持热部署,提高开发者的开发效率,无需手动重启Spring Boot ...

  5. JVM堆内存调优

    堆大小设置JVM 中最大堆大小有三方面限制:相关操作系统的数据模型(32-bt还是64-bit)限制:系统的可用虚拟内存限制:系统的可用物理内存限制.32位系统下,一般限制在1.5G~2G:64为操作 ...

  6. 关于Spring的配置文件的注解使用

    从Spring3.0,@Configuration用于定义配置类,可替换xml配置文件,被注解的类内部包含有一个或多个被@Bean注解的方法, 这些方法将会AnnotationConfigApplic ...

  7. C#学习笔记(四):switch语句

    条件语句 switch语句快速生成枚举方法,复制枚举名在switch()里,双击TAB 快速生成方法,用纠错功能 随机数 using System; using System.Collections. ...

  8. 【TCP/IP详解 卷一:协议】TCP定时器 小结

    前言 在有关TCP的章节中,介绍了四种定时器,它们体现了TCP的可靠性,其中最重要的 就是重传定时器了,剩下的定时器都是为了解决TCP的理解上的一些问题而设置的. 四种定时器: 2MSL定时器,出现在 ...

  9. Python Sip [RuntimeError: the sip module implements API v11.0 to v11.2 but the PyQt5.QtCore module requires API v11.3]

    不知道原因,尝试卸载.编译安装均失败.只有这样曲线救国 import matplotlib matplotlib.use("WXAgg",warn=True) import mat ...

  10. Django 综合篇

    前面,已经将Django最主要的五大系统介绍完毕,除了这些主要章节,还有很多比较重要的内容,比如开发流程相关.安全.本地化与国际化.常见工具和一些框架核心功能.这些内容的篇幅都不大,但整合起来也是Dj ...