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个 ...
随机推荐
- 【LeetCode】135. Candy
Candy There are N children standing in a line. Each child is assigned a rating value. You are giving ...
- Google map API V3
本文主要总结Google map API V3使用中最简单也是最常见的一些操作以及相关概念,如果需要更加详细的信息,请直接阅读Google提供的关于map的文档. google map api v3文 ...
- python学习笔记——高阶函数map()
满足以下两点中任意一点,即为高阶函数: 1.函数接收一个或多个函数作为参数 2.函数返回一个函数 1 描述 用函数和可迭代对象中每一个元素作为参数,计算出新的迭代对象 map() 会根据提供的函数对指 ...
- PLSQL_性能优化效能跟踪工具DBMS_PROFILER分析(案例)
2014-06-01 Created By BaoXinjian
- webDAV服务的开启以及客户端的上传、下载、删除、新建文件夾、列表的代码(C#)
windows server 2003开启webDAV服务 1. 启动“IIS管理器”选择“WEB服务扩展”,选择“WEBDAV”的允许按钮启动WEBDAV功能 2.建立一个虚拟目录,对应到一个本地目 ...
- WordPress For SAE进入后台
今天遇到一个非常easy可是花了我半个小时的问题:怎样进入WordPress For SAE后台. 介于百度上没有搜索到.所以写了这篇博客,简单,but有用. 首先我们会訪问自己的网站:独立游戏者er ...
- C#预定义类型
C#提供了16中预定义类型,其中包括13种简单类型和三种非简单类型: 所有预定义类型的名称全部由小写字母组成.预定义的简单类型包括以下3种:11种数值类型.一种Unicode字符类型char.一种布尔 ...
- 【转】sql server存储过程中SELECT 与 SET 对变量赋值的区别
转自:http://www.cnblogs.com/micheng11/archive/2008/07/08/1237905.html SQL Server 中对已经定义的变量赋值的方式用两种,分别是 ...
- CentOS配置SSH远程连接
本文为大家介绍Centos中配置SSH远程连接的方法,只是简单配置,供初学者参考. 1.配置IP#setup 选择 NetWork configuration 选择 Device configurat ...
- 【Android】8.1 主题基本用法
分类:C#.Android.VS2015: 创建日期:2016-02-17 一.创建本章示例主界面 1.界面截图 2.MainActivity.cs文件中对应的代码 在CreateChItems()方 ...