sgu120

10 篇文章 0 订阅

题目

</pre><p><table width="95%" style="font-family: Simsun;"><tbody><tr><td style="font-size: 9pt;"><h3><strong></strong><p align="CENTER">120. Archipelago</p></h3><p align="CENTER">time limit per test: 0.25 sec. memory limit per test: 4096 KB</p><p align="JUSTIFY"></p><p align="JUSTIFY">Archipelago Ber-Islands consists of <em>N</em> islands that are vertices of equiangular and equilateral <em>N</em>-gon. Islands are clockwise numerated. Coordinates of island <em>N<sub>1</sub></em> are <em>(x<sub>1</sub>, y<sub>1</sub>)</em>, and island <em>N<sub>2</sub></em> – <em>(x<sub>2</sub>, y<sub>2</sub>)</em>. Your task is to find coordinates of all <em>N</em> islands.</p><p align="JUSTIFY"></p><strong></strong><p align="JUSTIFY">Input</p><p align="JUSTIFY">In the first line of input there are <em>N, N<sub>1</sub></em> and <em>N<sub>2</sub> (3<span style="font-family:Symbol;">£</span> N<span style="font-family:Symbol;">£</span> 150, 1<span style="font-family:Symbol;">£</span> N<sub>1</sub>,N<sub>2</sub><span style="font-family:Symbol;">£</span>N, N<sub>1</sub><span style="font-family:Symbol;">¹</span>N<sub>2</sub>) </em>separated by spaces. On the next two lines of input there are coordinates of island <em>N<sub>1</sub></em> and <em>N<sub>2</sub></em> (one pair per line) with accuracy <em>4</em> digits after decimal point. Each coordinate is more than <em>-2000000</em> and less than <em>2000000</em>.</p><p align="JUSTIFY"></p><strong></strong><p align="JUSTIFY">Output</p><p align="JUSTIFY">Write <em>N</em> lines with coordinates for every island. Write coordinates in order of island numeration. Write answer with 6 digits after decimal point.</p><p align="JUSTIFY"></p><p align="JUSTIFY">Sample Input</p><span style="font-family:Courier New;"></span><pre>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

Author: Michael R. Mirzayanov
Resource: PhTL #1 Training Contests
Date: Fall 2001


题解:

通过两个顶点坐标求出正多边形的中点坐标,在求出其外接圆半径,然后三角函数反三角函数各种虐就可以得到每一个点的坐标。。。


代码:

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#define dis(a, b) sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))
#define pai 3.1415926535897932384626
using namespace std;
struct point
{
	double x, y;
}v[155], now, mid, o;
int n, a, b;
double drt, r, pai;
int main()
{
	scanf("%d%d%d", &n, &a, &b);
	scanf("%lf%lf%lf%lf", &v[a].x, &v[a].y, &v[b].x, &v[b].y);
	if (a > b) swap(a, b);
	mid.x = (v[a].x + v[b].x) / 2;
	mid.y = (v[a].y + v[b].y) / 2;
	r = dis(v[a], v[b]) / sin(pai * (b - a) / n) / 2;
	o.x = mid.x + (v[b].y - v[a].y) / tan(pai * (b - a) / n) / 2;
	o.y = mid.y - (v[b].x - v[a].x) / tan(pai * (b - a) / n) / 2;
	pai = asin((v[a].y - o.y) / r);
	if (acos((v[a].x - o.x) / r) > pai / 2)
		if (pai >= -1e10) pai = pai - pai;
		else pai = -pai - pai;
	for (int i = 1; i <= n; i++)
		if (i != a && i != b)
		{
			drt = pai + 2 * pai * (a - i) / n;
			v[i].x = o.x + r * cos(drt);
			v[i].y = o.y + r * sin(drt);
		}
	for (int i = 1; i <= n; i++) printf("%.6lf %.6lf\n", v[i].x, v[i].y);
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值