bzoj 1502 计算几何 分类: bzoj 2015-03-09 22:23 54人阅读 评论(0) 收藏
2015-03-09 22:23
423 查看
计算几何就是麻烦,
我只想学学辛普森函数和自适应辛普森算法,
计算几何其他内容。。。就理性放弃吧。。。。。。
S(l,r)=(f(l)+4∗f(mid)+f(r))/6
我只想学学辛普森函数和自适应辛普森算法,
计算几何其他内容。。。就理性放弃吧。。。。。。
S(l,r)=(f(l)+4∗f(mid)+f(r))/6
#include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<algorithm> #define pow2(x) ((x)*(x)) const int MAXN = 600 ,INF = 1<<30;const double eps = 0.0000001; int n ; double alpha; double r0[MAXN] = {0}; double h[MAXN] = {0}; struct circle{double x,r;}c[MAXN] = {0}; struct line{double x1,x2,y1,y2;}l[MAXN] = {0}; int dcmp(const double &x) { if(fabs(x) < eps)return 0; else if(x > 0) return 1; else return -1; } double f(double x) { double h = 0; for(int i = 1 ;i <= n ;i++) { if(c[i].x - c[i].r <= x && x <= c[i].x + c[i].r) { h = std::max(h , sqrt(pow2(c[i].r) - pow2(c[i].x - x))); } if(i < n && l[i].x1 <= x && x <= l[i].x2) { h = std::max(h , l[i].y1+(x-l[i].x1)*(l[i].y2-l[i].y1)/(l[i].x2-l[i].x1)); } } return h; } double simpson(const double &fl,const double &fm,const double &fr,const double &l,const double &r){return (r - l)*(fl + 4*fm + fr)/6;} double fun_simpson(const double fll,const double fm ,const double frr ,const double ll ,const double rr) { double m = (ll + rr)/2 , lm = (ll + m)/2, mr = (m + rr)/2, flm = f(lm),fmr = f(mr); double s = simpson(fll,fm,frr,ll,rr) ; double sl = simpson(fll,flm,fm,ll,m) ; double sr = simpson(fm,fmr,frr,m,rr); if(dcmp(s - (sl + sr)) != 0) { sl = fun_simpson(fll,flm,fm,ll,m); sr = fun_simpson(fm,fmr,frr,m,rr); s = sl + sr; } return s; } int main() { double ans = 0, ll = INF, rr = -INF , mid; #ifndef ONLINE_JUDGE freopen("bzoj1502.in","r",stdin); freopen("bzoj1502.out","w",stdout); #endif scanf("%d",&n); n = n + 1; scanf("%lf",&alpha); for(int i = 1 ; i <= n ;i++) { scanf("%lf", &h[i]); h[i] += h[i-1]; } for(int i = 1 ; i < n ;i++) scanf("%lf", &r0[i]); for(int i = 1 ; i <= n ;i++) { c[i].r = r0[i]; c[i].x = h[i] / tan(alpha); ll = std::min(ll ,c[i].x - c[i].r); rr = std::max(rr ,c[i].x + c[i].r); } for(int i = 1 ; i < n ;i++) { l[i].x1 = c[i].x + c[i].r*(c[i].r-c[i+1].r)/(c[i+1].x-c[i].x); l[i].y1 = sqrt(pow2(c[i].r) - pow2(l[i].x1-c[i].x)); l[i].x2 = c[i+1].x + c[i+1].r*(c[i].r-c[i+1].r)/(c[i+1].x-c[i].x); l[i].y2 = sqrt(pow2(c[i+1].r) - pow2(l[i].x2-c[i+1].x)); } mid = (ll + rr)/2; ans = fun_simpson(f(ll),f(mid),f(rr),ll,rr)*2; printf("%.2lf",ans); #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0; }
相关文章推荐
- bzoj 3572 分类: bzoj 2015-03-29 22:23 45人阅读 评论(0) 收藏
- android中两种方式打开网页 分类: Android开发 2014-05-30 10:57 54人阅读 评论(0) 收藏
- 安装APP损坏,出现[INSTALL_FAILED_DEXOPT]的解决办法 分类: Android安装及配置 2014-06-27 22:23 118人阅读 评论(0) 收藏
- C#中的线程(上)-入门 分类: C# 线程 2015-03-09 10:56 53人阅读 评论(0) 收藏
- bzoj 2038 分类: bzoj templates 2015-03-26 20:28 41人阅读 评论(0) 收藏
- android编程如何把现有的背景图片… 分类: Android开发 2014-05-30 10:53 54人阅读 评论(0) 收藏
- C#类型 分类: C# 2015-03-09 08:44 202人阅读 评论(0) 收藏
- 分类算法简介 分类: B10_计算机基础 2015-03-09 11:08 257人阅读 评论(0) 收藏
- C#多线程(上) 分类: C# 线程 2015-03-09 10:35 174人阅读 评论(0) 收藏
- bzoj 2304 [Apio 2011 path] 分类: bzoj apio 2015-05-01 20:14 46人阅读 评论(0) 收藏
- tkinter计算字符串的值 分类: python 小练习 python 2013-06-30 17:11 299人阅读 评论(0) 收藏
- Median of Two Sorted Arrays 分类: Leetcode(线性表) 2015-02-04 09:05 54人阅读 评论(0) 收藏
- #小练习:计算Fibonacci数列的前10项 分类: python 小练习 2013-04-22 11:50 289人阅读 评论(0) 收藏
- eclipse 启动一闪而过启动不起来,Job found still running after platform shutd 分类: eclipse 2015-03-09 21:27 75人阅读 评论(0) 收藏
- hi3531串口波特率计算 分类: HI3531 arm-linux-Ubuntu 2013-12-14 09:11 1026人阅读 评论(0) 收藏
- SQL 计算两个时间之差 分类: SQL Server 2014-07-04 10:57 119人阅读 评论(0) 收藏
- Bzoj 1036 树的统计 分类: ACM TYPE 2014-12-29 18:55 72人阅读 评论(0) 收藏
- Android MediaPlayer播放prepareAsync called in state 8解决办法 分类: Android多媒体 2015-01-08 10:16 54人阅读 评论(0) 收藏
- eclipse 启动一闪而过启动不起来,Job found still running after platform shutd 分类: eclipse 2015-03-09 21:27 74人阅读 评论(0) 收藏
- C#多线程(下) 分类: C# 线程 2015-03-09 10:41 153人阅读 评论(0) 收藏