BZOJ2178 圆的面积并(simpson积分)
板子题。可以转一下坐标防止被卡。精度和常数实在难以平衡。
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define double long double
#define N 1010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n;
const double PI=acos(-1.0);
double x[N],y[N],r[N];
struct data
{
double x;int op;
bool operator <(const data&a) const
{
return x<a.x;
}
}a[N<<1];
const double eps=1E-7;
double f(double k)
{
int m=0;
for (int i=1;i<=n;i++)
if (fabs(x[i]-k)<r[i])
{
double t=sqrt(r[i]*r[i]-(x[i]-k)*(x[i]-k));
a[++m].x=y[i]-t,a[m].op=1;
a[++m].x=y[i]+t,a[m].op=-1;
}
sort(a+1,a+m+1);
double ans=0,cur;int u=0;
for (int i=1;i<=m;i++)
{
if (u==0) cur=a[i].x;
u+=a[i].op;
if (u==0) ans+=a[i].x-cur;
}
return ans;
}
double simpson(double l,double r)
{
return (r-l)*(f(l)+f(r)+4*f((l+r)/2))/6;
}
double calc(double l,double r,double simp)
{
double mid=(l+r)/2,x=simpson(l,mid),y=simpson(mid,r);
if (fabs(x+y-simp)<eps) return x+y;
else return calc(l,mid,x)+calc(mid,r,y);
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bzoj2178.in","r",stdin);
freopen("bzoj2178.out","w",stdout);
const char LL[]="%I64d\n";
#else
const char LL[]="%lld\n";
#endif
n=read();double L=2000,R=-2000;
for (int i=1;i<=n;i++)
{
x[i]=read(),y[i]=read(),r[i]=read();
double u=x[i]*sin(PI/3)+y[i]*cos(PI/3),v=x[i]*cos(PI/3)-y[i]*sin(PI/3);
x[i]=u,y[i]=v;
L=min(L,x[i]-r[i]),R=max(R,x[i]+r[i]);
}
#undef double
printf("%.3f",(double)calc(L,R,simpson(L,R)));
return 0;
}
BZOJ2178 圆的面积并(simpson积分)的更多相关文章
- BZOJ 2178 圆的面积并 ——Simpson积分
[题目分析] 史上最良心样例,史上最难调样例. Simpson积分硬上. 听说用long double 精度1e-10才能过. 但是double+1e-6居然过了. [代码] #include < ...
- [SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并
[SPOJ-CIRU]The area of the union of circles/[BZOJ2178]圆的面积并 题目大意: 求\(n(n\le1000)\)个圆的面积并. 思路: 对于一个\( ...
- BZOJ 2178: 圆的面积并 [辛普森积分 区间并]
2178: 圆的面积并 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1740 Solved: 450[Submit][Status][Discus ...
- BZOJ2178: 圆的面积并(格林公式)
题面 传送门 题解 好神仙-- 先给几个定义 平面单连通区域:设\(D\)是平面内一区域,若属于\(D\)内任一简单闭曲线的内部都属于\(D\),则称\(D\)为单连通区域.通俗地说,单连通区域是没有 ...
- BZOJ2178 圆的面积并 计算几何 辛普森积分
原文链接https://www.cnblogs.com/zhouzhendong/p/BZOJ2178.html 题目传送门 - BZOJ2178 题意 给出 $n(n\leq 1000)$ 个圆,求 ...
- bzoj 2178 圆的面积并 —— 辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...
- bzoj2178: 圆的面积并
Description 给出N个圆,求其面积并 Input 先给一个数字N ,N< = 1000 接下来是N行是圆的圆心,半径,其绝对值均为小于1000的整数 Output 面积并,保留三位小数 ...
- bzoj 2178 圆的面积并——辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...
- BZOJ 2178: 圆的面积并 (辛普森积分)
code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...
随机推荐
- ubuntu和windows系统双系统的开机选项界面有很多无关选项
我的电脑是双系统,在进入系统选项的时候有很多无关的选项, 例如: 解决的方法是在终端输入 sudo gedit /boot/grub/grub.cfg 把文件多余的开机选项删除例如: 保存就可以,开机 ...
- C语言程序设计II—第五周教学
第五周教学总结(25/3-31/3) 教学内容 本周的教学内容为:第七章 数组 7.3 字符串. 课前准备 在博客园发布作业:2019春第五周作业 第四周作业讲解视频:A Programing Vid ...
- MYSQL表情存储数据库报错
1.windows安装5.5.5.9的服务器 2.打开window服务找到mysql的服务,右键属性查看路径 3.打开路径,修改mysql配置文件my.ini 4.修改[client]中的defaul ...
- Struts学习总结-02 上传文件
Struts 2框架提供了内置支持处理文件上传使用基于HTML表单的文件上传.上传一个文件时,它通常会被存储在一个临时目录中,他们应该由Action类进行处理或移动到一个永久的目录,以确保数据不丢失. ...
- python winpdb远程调试
1.使用rpdb2.start_embedded_debugger ,注意要将参数fAllowRemote 设置为True 2.winpdb前端GUI使用python2 3.rpdb兼容python2 ...
- Scala学习(四)---映射和元组
映射和元组 摘要: 一个经典的程序员名言是:"如果只能有一种数据结构,那就用哈希表吧".哈希表或者更笼统地说映射,是最灵活多变的数据结构之一.映射是键/值对偶的集合.Scala有一个通用的叫法:元组, ...
- vue-cli 3.0 axios 跨域请求代理配置及生产环境 baseUrl 配置
1. 开发环境跨域配置 在 vue.config.js 文件中: module.exports = { runtimeCompiler: true, publicPath: '/', // 设置打包文 ...
- poj3126 Prime Path(c语言)
Prime Path Description The ministers of the cabinet were quite upset by the message from the Chief ...
- js方法中拼接html时点击事件中拼接字符串参数
1,代码 var html = '<a href="#" onclick="tableDelete(\''+ row.labelid +'\')"> ...
- Bing词典分析
0x01 Bug测试结果 本次测试的是Bing词典wp版本V4.5.2,经过测试,共发现如下Bug. 1.更新后,旧版本首页的每日单词与文章推荐不能重新获得,部分搜索历史记录丢失. 2.在单词挑战模式 ...