SGU 120 Archipelago (简单几何)
|
120. Archipelago time limit per test: 0.25 sec. 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),
Input In the first line of input there are N, N1 and N2 (3£ N£ 150, 1£ N1,N2£N,
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 Sample Output 1.000000 0.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 (简单几何)的更多相关文章
- Python下opencv使用笔记(二)(简单几何图像绘制)
简单几何图像一般包含点.直线.矩阵.圆.椭圆.多边形等等.首先认识一下opencv对像素点的定义. 图像的一个像素点有1或者3个值.对灰度图像有一个灰度值,对彩色图像有3个值组成一个像素值.他们表现出 ...
- Codeforces 935 简单几何求圆心 DP快速幂求与逆元
A #include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #def ...
- Archipelago - SGU 120(计算几何向量旋转)
题目大意:有一个正N边形,然后给出两个点,求出剩余的点的坐标. 分析:向量旋转可以求出坐标,顺时针旋转时候,x = x'*cos(a) + y'*sin(a), y=-x'*sin(a) + y'*c ...
- 简单几何(线段相交) POJ 2653 Pick-up sticks
题目传送门 题意:就是小时候玩的一种游戏,问有多少线段盖在最上面 分析:简单线段相交,队列维护当前最上的线段 /******************************************** ...
- osg for android (一) 简单几何物体的加载与显示
1. 首先需要一个OSG for android的环境. (1).NDK 现在Eclipse 对NDK已经相当友好了,已经不需要另外cygwin的参与,具体可以参考 Android NDK开发篇(一) ...
- HDU 6206 青岛网络赛1001 高精度 简单几何
给出的数据1e12规模,常规判点是否在圆范围内肯定要用到半径,求得过程中无法避免溢出,因此用JAVA自带的浮点大数运算,和个ZZ一样比赛中eclipse出现问题,而且太久没写JAVA语法都不清楚变量忘 ...
- CodeForces 703C Chris and Road (简单几何)
题意:有一个n边形的汽车向以速度v向x轴负方向移动,给出零时时其n个点的坐标.并且有一个人在(0,0)点,可以以最大速度u通过w宽的马路,到达(0,w)点.现在要求人不能碰到汽车,人可以自己调节速度. ...
- Jack Straws POJ - 1127 (简单几何计算 + 并查集)
In the game of Jack Straws, a number of plastic or wooden "straws" are dumped on the table ...
- codeforces 394E Lightbulb for Minister 简单几何
题目链接:点我点我 题意:给定n个点. 以下n行给出这n个点坐标. 给定m个点,以下m行给出这m个点坐标. 这m个点是一个凸包,顺时针给出的. 问:在凸包上随意找一个点(x, y) 使得这个点距离n个 ...
随机推荐
- [转]动态加载javascript
动态加载script到页面大约有俩方法 第一种就是利用ajax方式,把script文件代码从后台加载到前台,然后对加载到的内容通过eval()执行代码. 第二种是,动态创建一个script标签,设置其 ...
- pandas 的数据结构Series与DataFrame
pandas中有两个主要的数据结构:Series和DataFrame. [Series] Series是一个一维的类似的数组对象,它包含一个数组数据(任何numpy数据类型)和一个与数组关联的索引. ...
- java JAXB + STAX(是一种针对XML的流式拉分析API)读取xml
JDK1.5需要添加jar包,1.6以后就不需要了<dependency> <groupId>stax</groupId> <artifactId>st ...
- AVL平衡二叉搜索树原理及各项操作编程实现
C语言版 #include<stdio.h> #include "fatal.h" struct AvlNode; typedef struct AvlNode *Po ...
- OC 中new与alloc/init的差别
英文具体解释:http://macresearch.org/difference-between-alloc-init-and-new 1.在实际开发中非常少会用到new.一般创建对象咱们看到的全是[ ...
- vim打造简易C语言编辑器(在用2016.7.10)
vim和C语言都需要长期的学习,才能够精通,我制作了这个简单的笔记,主要的作用是,不要在重复的,反复的找同一样东西了,积累是成功的关键. 1. 安装pathogen插件管理器. 在官网下载pathog ...
- [k8s]通过svc来访问集群podhttp://api:8080/api/v1/namespaces/default/services/mynginx/proxy/
以往的套路是,安装完成k8s集群后-->安装dns-->安装ingress以便外面访问(或者映射nodeport方式) 如果你不想做任何关于ingress/nodeport一些操作.想通过 ...
- 【Android】Java堆栈溢出的解决办法
分类:C#.Android.VS2015: 创建日期:2016-03-18 随着项目中添加的.jar和.so文件越来越多,编译MyDemos项目时,可能会出现Java堆栈溢出的错误,提示让增加Java ...
- hdoj 1166 敌兵布阵 线段数和树状数组
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- ny613 免费馅饼
免费馅饼 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人 ...