HDU1724 Ellipse
Look this sample picture:
A ellipses in the plane and center in point O. the L,R lines will be vertical through the X-axis. The problem is calculating the blue intersection area. But calculating the intersection area is dull, so I have turn to you, a talent of programmer. Your task is tell me the result of calculations.(defined PI=3.14159265 , The area of an ellipse A=PI*a*b )
InputInput may contain multiple test cases. The first line is a positive integer N, denoting the number of test cases below. One case One line. The line will consist of a pair of integers a and b, denoting the ellipse equation , A pair of integers l and r, mean the L is (l, 0) and R is (r, 0). (-a <= l <= r <= a).OutputFor each case, output one line containing a float, the area of the intersection, accurate to three decimals after the decimal point.Sample Input
2
2 1 -2 2
2 1 0 2
Sample Output
6.283
3.142
几何
simpson积分强行搞
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
const double eps=1e-;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*-''+ch;ch=getchar();}
return x*f;
}
int a,b;
inline double f(double x){
return b*sqrt((double)-(x*x/(double)a/a));
}
inline double sim(double l,double r){
return (r-l)/*(f(l)+*f((l+r)/)+f(r));
}
double solve(double l,double r){
double mid=(l+r)/;
double res=sim(l,r);
// printf("l:%.3f r:%.3f res:%.3f\n",l,r,res);
if(fabs(sim(l,mid)+sim(mid,r)-res)<=eps)return res;
return solve(l,mid)+solve(mid,r);
}
int main(){
int T=read();
double l,r;
while(T--){
a=read();b=read();
l=read();r=read();
double ans=solve(l,r);
printf("%.3f\n",*ans);
}
return ;
}
最新文章
- ASP.NET MVC 视图(三)
- Unity自动寻路Navmesh之高级
- NULL指针、零指针、野指针
- chrome浏览器调用 ajax 提示net::ERR_INCOMPLETE_CHUNKED_ENCODING问题解决方案,以及 Response.Close 和 Response.End 的一些问题。
- Struts2进行url重写
- MFC中控制COMBOBOX控件的下拉框高度
- Windows 2003/2008更改远程桌面端口脚本
- Part 3 talking about constraint in sql
- 解决maven仓库有jar包但是maven程序无法下载仓库jar包
- 类(class)能不能自己继承自己(转)
- Java 并发 线程的优先级
- foreach 循环的应用传值
- 关于CGI:Tomcat、PHP、Perl、Python和FastCGI之间的关系
- JDBC(二)之JDBC处理CLOB和BLOB及事务与数据库元数据获取
- requests-post请求
- Spring 初学笔记
- 记一次 net 使用 data.oracleclient 使用错误OCIEnvCreate 失败, 返回代码为-1
- 关闭AutoCAD 2019快速访问工具栏的web和moblie保存文件功能
- 【转】ubuntu 12.04下如何开启 NFS 服务 &; 设置
- php 文件上传类,功能相当齐全,留作开发中备用吧。