2054.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 32 行

CPP
32
字号
/*  This Code is Submitted by wywcgs for Problem 2054 on 2006-01-07 at 21:19:40 */ 
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

const int MAX = 16;
const double R = 1.0;

int main()
{
	int n, i, j;
	double x[MAX], y[MAX];
	
	while(scanf("%d", &n) != EOF && n != 0) {
		for(i = 0; i < n; i++) scanf("%lf", &x[i]), y[i] = R;
		sort(x, x+n);
		for(i = 1; i < n; i++) {
			for(j = 0; j < n - i; j++) {
				double l = sqrt((x[j]-x[j+1])*(x[j]-x[j+1])+(y[j]-y[j+1])*(y[j]-y[j+1]));
				double d = sqrt(4*R*R-l*l/4);
				double a = (x[j]+x[j+1])/2 - d*(y[j+1]-y[j])/l;
				double b = (y[j]+y[j+1])/2 + d*(x[j+1]-x[j])/l;
				x[j] = a, y[j] = b;
			}
		}
		printf("%.4lf %.4lf\n", x[0], y[0]);
	}
	
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?