POJ 2194/POJ 2850
2013-02-24 23:57
239 查看
题意:
一堆圆,R=1,已知底层各个的圆心坐标,求最上面一个圆心的坐标。
题解:
模拟,尽量少使用反三角函数,不得不用时,尽量用atan2即可。
View Code
依旧在写水题。。。
一堆圆,R=1,已知底层各个的圆心坐标,求最上面一个圆心的坐标。
题解:
模拟,尽量少使用反三角函数,不得不用时,尽量用atan2即可。
View Code
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <cmath> #define N 222 using namespace std; struct PO { double x,y; }p ; int n; inline bool cmp(const PO &a,const PO &b) { return a.x<b.x; } inline void read() { for(int i=1;i<=n;i++) { scanf("%lf",&p[1][i].x); p[1][i].y=1.0; } sort(p[1]+1,p[1]+1+n,cmp); } inline PO rotate(PO a,double hd) { PO c; c.x=a.x*cos(hd)-a.y*sin(hd); c.y=a.x*sin(hd)+a.y*cos(hd); return c; } inline double getlen(PO &a)//向量的模 { return sqrt(a.x*a.x+a.y*a.y); } inline double getdis2(PO &a,PO &b) { return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y); } inline void go() { int c=1; while(n>1) { c++; for(int i=1;i<n;i++) { double af=atan2(sqrt(4.0-getdis2(p[c-1][i],p[c-1][i+1])*0.25),sqrt(getdis2(p[c-1][i],p[c-1][i+1]))*0.5); //atan2精度较高,其他的反三角函数精度都比较差。。。 PO s; s.y=p[c-1][i+1].y-p[c-1][i].y; s.x=p[c-1][i+1].x-p[c-1][i].x; double k=2.0/getlen(s); s.y*=k; s.x*=k; s=rotate(s,af); p[c][i].y=p[c-1][i].y+s.y; p[c][i].x=p[c-1][i].x+s.x; } n--; } printf("%.4lf %.4lf\n",p[c][1].x,p[c][1].y); } int main() { while(scanf("%d",&n),n) read(),go(); return 0; }
依旧在写水题。。。
相关文章推荐
- POJ 2194 2850 Stacking Cylinders
- zoj 2403 || poj 2194 || poj 2850 Stacking Cylinders
- POJ 2194 2850 计算几何
- POJ 2194 Stacking Cylinders(两圆相切求圆心坐标)
- poj 2194(字符串的DP)
- POJ 2850 Stacking Cylinders 简单计算几何
- POJ - 2194
- poj 2194 Stacking Cylinders 计算几何之向量旋转
- poj 1328
- [POJ_1008]Maya Calendar
- POJ 3299 Humidex
- poj 1422Air Raid--最小路径覆盖
- poj 1270 Following Orders
- POJ2001 Shortest Prefixes
- POJ 1815 Friendship ★(字典序最小点割集)
- poj 3140 Contestants Division(树形dp? dfs计数+枚举)
- poj-2486-树形dp
- 求最长连续公共子序列 POJ 3080
- poj 3041
- 【POJ】3905 Perfect Election 2-sat