BZOJ 2178 圆的面积并 ——Simpson积分
【题目分析】
史上最良心样例,史上最难调样例。
Simpson积分硬上。
听说用long double 精度1e-10才能过。
但是double+1e-6居然过了。
【代码】
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib> #include <map>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 1005
#define eps 1e-6
#define db double
#define ll long long
#define ldb long double
#define inf 0x3f3f3f3f
#define F(i,j,k) for (int i=j;i<=k;++i)
#define D(i,j,k) for (int i=j;i>=k;--i) void Finout()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
} int Getint()
{
int x=0,f=1; char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-1; ch=getchar();}
while (ch>='0'&&ch<='9') {x=x*10+ch-'0'; ch=getchar();}
return x*f;
} int n,cnt=0,tag[maxn],tot;
struct Circle{int x,y,r;}c[maxn];
struct Segment{db l,r;}a[maxn]; bool cmp(Segment x,Segment y)
{return x.l==y.l?x.r<y.r:x.l<y.l;} bool cmp1(Circle a,Circle b)
{return a.r<b.r;} db get(db x)
{
int cnt=0;
F(i,1,n) if (fabs(c[i].x-x)<=c[i].r-eps)
{
db tmp=sqrt(c[i].r*c[i].r-(x-c[i].x)*(x-c[i].x));
a[++cnt]=(Segment){c[i].y-tmp,c[i].y+tmp};
}
sort(a+1,a+cnt+1,cmp);
db h=-inf,ans=0;
F(i,1,cnt)
{
if (a[i].l>h) ans+=a[i].r-a[i].l,h=a[i].r;
else if (a[i].r>h) ans+=a[i].r-h,h=a[i].r;
}
return ans;
} db cal(db l,db r)
{
db mid=(l+r)/2,fl=get(l),fr=get(r),fm=get(mid);
return (r-l)/6*(fl+fr+4*fm);
} db simpson(db l,db r)
{
db mid=(l+r)/2,s1=cal(l,r),s2=cal(l,mid)+cal(mid,r);
if (fabs(s2-s1)<=eps) return s2;
else return simpson(l,mid)+simpson(mid,r);
} int main()
{
Finout();n=Getint();
F(i,1,n)
{
c[i].x=Getint();
c[i].y=Getint();
c[i].r=Getint();
}
sort(c+1,c+n+1,cmp1);
F(i,1,n-1) F(j,i+1,n)
{
if ((c[i].x-c[j].x)*(c[i].x-c[j].x)+(c[i].y-c[j].y)*(c[i].y-c[j].y)<=(c[j].r-c[i].r)*(c[j].r-c[i].r))
{
tag[i]=1;
break;
}
}
F(i,1,n) if (!tag[i]) c[++tot]=c[i];
n=tot;
printf("%.3f\n",simpson(-2000.0,2000.0));
}
BZOJ 2178 圆的面积并 ——Simpson积分的更多相关文章
- BZOJ 2178: 圆的面积并 [辛普森积分 区间并]
2178: 圆的面积并 Time Limit: 20 Sec Memory Limit: 259 MBSubmit: 1740 Solved: 450[Submit][Status][Discus ...
- bzoj 2178 圆的面积并 —— 辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 先看到这篇博客:https://www.cnblogs.com/heisenberg- ...
- bzoj 2178 圆的面积并——辛普森积分
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2178 把包含的圆去掉.横坐标不相交的一段一段圆分开算.算辛普森的时候预处理 f( ) ,比如 ...
- BZOJ 2178: 圆的面积并 (辛普森积分)
code #include <set> #include <cmath> #include <cstdio> #include <cstring> #i ...
- [BZOJ 2178] 圆的面积并 【Simpson积分】
题目链接:BZOJ - 2178 题目分析 用Simpson积分,将圆按照 x 坐标分成连续的一些段,分别用 Simpson 求. 注意:1)Eps要设成 1e-13 2)要去掉被其他圆包含的圆. ...
- bzoj 2178 圆的面积并【simpson积分】
直接套simpson,f可以直接把圆排序后扫一遍所有圆,这样维护一个区间就可以避免空段. 然而一定要去掉被其他圆完全覆盖的圆,否则会TLE #include<iostream> #incl ...
- 【BZOJ】2178: 圆的面积并
http://www.lydsy.com/JudgeOnline/problem.php?id=2178 题意:给出n<=1000个圆,求这些圆的面积并 #include <cstdio& ...
- BZOJ 1845: [Cqoi2005] 三角形面积并 (辛普森积分)
大力辛普森积分 精度什么的搞了我好久- 学到了Simpson的一个trick 深度开11,eps开1e-4.跑的比有些扫描线还快- CODE #include <bits/stdc++.h> ...
- BZOJ 1502 月下柠檬树(simpson积分)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1502 题意:给出如下一棵分层的树,给出每层的高度和每个面的半径.光线是平行的,与地面夹角 ...
随机推荐
- MySQL版本详解
一.版本说明 1.1.MySQL相关连接 MySQL官网:https://www.mysql.com/ MySQL下载:https://dev.mysql.com/downloads/mirrors/ ...
- python应用:经纬度匹配
需要安装第三方包:requests 本次经纬度匹配采用高德地图api,首先将gps坐标转化为高德地图的经纬度坐标,然后再根据转化后的坐标进行匹配. 本次匹配主要是获取距离给定经纬度最近的poi点地址信 ...
- JavaScript之原型 Prototype
1.我们所创建的每一个函数,解析器都会向函数中添加一个属性prototype.这个属性对应着一个对象,这个对象就是我们所谓的原型对象.如果函索作为普通函数调用prototype没有任何作用. 当函数以 ...
- C语言实现二分查找
二分查找优势:比顺序查找更有效率 特点:元素按顺序排列 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include ...
- Redis Handle
package com.jn.baseservice.utils; import com.jn.baseservice.GlobalEntiy.Entity; import com.google.gs ...
- COURSES POJ1469(模板)
Description Consider a group of N students and P courses. Each student visits zero, one or more than ...
- Notepad++删除空行的多种实现办法
Notepad++支持基础的正则表达式,同时由于自身丰富的插件和功能,所以删除空行或有空格的空行,有多种实现办法,条条大路通罗马,闪电博客抛砖引玉,供大家参考. 一.删除空行(不包括有空格类符号的空行 ...
- XenServer设置master,摧毁故障主机
XenServer pool 移除server 设置master 这分为Pool Master是正常还是异常2种情况: 正常情况下可能要对Pool Master做一些停机维护,比如换内存条啥的,此时在 ...
- Linux 服务器 监控命令
1 top top类似于windows下面的资源管理器.不仅能够从服务器整体上展示服务器的大致情况,还可以看到具体进程 耗费资源的情况. 展示内存.cpu.交换分区等信息 如上图: 第一行主要描述系统 ...
- node 发送 post 请求 get请求。
因为我们部门打算用node请求restful 然后慢慢替换掉服务端,以后直接请求soa的接口,让前端的数据更贴切项目,因为我们服务端接口和app公用一套,由于业务的需求和版本不统一(例如app6.4的 ...