搬运别人的

https://vjudge.net/problem/SPOJ-CIRUT

//china no.1
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std; #define pi acos(-1)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
typedef long long LL;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-,,,,,-,-,};
const int dy[]={,,,-,-,,-,};
const int maxn=1e3+;
const int maxx=1e6+;
const double EPS=1e-;
const double eps=1e-;
const int mod=;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return ;}
while (c != '-' && (c < '' || c > '')){c = getchar();}sgn = (c == '-') ? - : ;ret = (c == '-') ? : (c - '');
while (c = getchar(), c >= '' && c <= ''){ret = ret * + (c - '');}ret *= sgn;return ;} inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<''||in>''))in=getchar();if(in=='-'){IsN=true;num=;}else if(in=='.'){IsD=true;num=;}
else num=in-'';if(!IsD){while(in=getchar(),in>=''&&in<=''){num*=;num+=in-'';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>=''&&in<=''){num+=Dec*(in-'');Dec*=0.1;}}
if(IsN) num=-num;return true;} void Out(LL a){if(a < ) { putchar('-'); a = -a; }if(a >= ) Out(a / );putchar(a % + '');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl; /*struct Point
{
double x, y;
Point(const Point& rhs): x(rhs.x), y(rhs.y) { } //拷贝构造函数
Point(double x = 0, double y = 0) : x(x), y(y) { }
inline void input()
{
scanf("%lf%lf",&x,&y);
}
inline void print()
{
printf("%.6lf %.6lf\n",x,y);
}
};*/ db sqr(db x)
{
return x*x;
}
int dcmp(double x)
{
if(fabs(x) < EPS) return ;
else return x < ? - : ;
} struct Circle
{
double x, y, r, angle;
int d;
Circle(){}
Circle(double xx, double yy, double ang = , int t = )
{
x = xx; y = yy; angle = ang; d = t;
}
void get()
{
scanf("%lf%lf%lf", &x, &y, &r);
d = ;
}
}; Circle cir[maxn],tp[maxn*];
double area[maxn]; double dis(Circle a,Circle b)
{
return sqrt(sqr(a.x - b.x) + sqr(a.y - b.y));
} double cross(Circle p0,Circle p1,Circle p2)
{
return (p1.x - p0.x) * (p2.y - p0.y) - (p1.y - p0.y) * (p2.x - p0.x);
}
//圆相交
int CirCrossCir(Circle p1, double r1,Circle p2, double r2,Circle &cp1,Circle &cp2)
{
double mx = p2.x - p1.x, sx = p2.x + p1.x, mx2 = mx * mx;
double my = p2.y - p1.y, sy = p2.y + p1.y, my2 = my * my;
double sq = mx2 + my2, d = -(sq - sqr(r1 - r2)) * (sq - sqr(r1 + r2));
if (d + eps < ) return ; if (d < eps) d = ; else d = sqrt(d);
double x = mx * ((r1 + r2) * (r1 - r2) + mx * sx) + sx * my2;
double y = my * ((r1 + r2) * (r1 - r2) + my * sy) + sy * mx2;
double dx = mx * d, dy = my * d; sq *= ;
cp1.x = (x - dy) / sq; cp1.y = (y + dx) / sq;
cp2.x = (x + dy) / sq; cp2.y = (y - dx) / sq;
if (d > eps) return ; else return ;
}
bool circmp(const Circle& u, const Circle& v)
{
return dcmp(u.r - v.r) < ;
} bool cmp(const Circle& u, const Circle& v)
{
if (dcmp(u.angle - v.angle)) return u.angle < v.angle;
return u.d > v.d;
}
//0.5*r*r*(K-sin(K))
double calc(Circle cir,Circle cp1,Circle cp2)
{
double ans = (cp2.angle - cp1.angle) * sqr(cir.r)
- cross(cir, cp1, cp2) + cross(Circle(, ), cp1, cp2);
return ans / ;
} void CirUnion(Circle cir[], int n)
{
Circle cp1, cp2;
sort(cir, cir + n, circmp);
for (int i = ; i < n; ++i)
for (int j = i + ; j < n; ++j)
if (dcmp(dis(cir[i], cir[j]) + cir[i].r - cir[j].r) <= )
cir[i].d++;
for (int i = ; i < n; ++i)
{
int tn = , cnt = ;
for (int j = ; j < n; ++j)
{
if (i == j) continue;
if (CirCrossCir(cir[i], cir[i].r, cir[j], cir[j].r,
cp2, cp1) < ) continue;
cp1.angle = atan2(cp1.y - cir[i].y, cp1.x - cir[i].x);
cp2.angle = atan2(cp2.y - cir[i].y, cp2.x - cir[i].x);
cp1.d = ; tp[tn++] = cp1;
cp2.d = -; tp[tn++] = cp2;
if (dcmp(cp1.angle - cp2.angle) > ) cnt++;
}
tp[tn++] = Circle(cir[i].x - cir[i].r, cir[i].y, pi, -cnt);
tp[tn++] = Circle(cir[i].x - cir[i].r, cir[i].y, -pi, cnt);
sort(tp, tp + tn, cmp);
int p, s = cir[i].d + tp[].d;
for (int j = ; j < tn; ++j)
{
p = s; s += tp[j].d;
area[p] += calc(cir[i], tp[j - ], tp[j]);
}
}
}
int n;
void solve()
{
for(int i=;i<n;i++)
cir[i].get();
me(area,);
CirUnion(cir,n);
for(int i=;i<=n;i++)
{
area[i]-=area[i+];
printf("[%d] = %.3f\n", i, area[i]);
}
} int main()
{
while(scanf("%d",&n)!=EOF)
solve();
}

圆的k次面积并的更多相关文章

  1. 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵

    题目描述: 一个N*M的矩阵,找出这个矩阵中所有元素的和不小于K的面积最小的子矩阵(矩阵中元素个数为矩阵面积) 输入: 每个案例第一行三个正整数N,M<=100,表示矩阵大小,和一个整数K 接下 ...

  2. 简单几何(圆与多边形公共面积) UVALive 7072 Signal Interference (14广州D)

    题目传送门 题意:一个多边形,A点和B点,满足PB <= k * PA的P的范围与多边形的公共面积. 分析:这是个阿波罗尼斯圆.既然是圆,那么设圆的一般方程:(x + D/2) ^ 2 + (y ...

  3. JS函数输出圆的半径和面积

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. Java作业 输入圆的半径计算输出圆的周长和面积

    package text1; import java.util.Scanner; public class text11 { public static void main(String[] args ...

  5. Gym-101158J Cover the Polygon with Your Disk 计算几何 求动圆与多边形最大面积交

    题面 题意:给出小于10个点形成的凸多边形 和一个半径为r 可以移动的圆 求圆心在何处的面积交最大,面积为多少 题解:三分套三分求出圆心位置,再用圆与多边形面积求交 #include<bits/ ...

  6. 牛客网暑期ACM多校训练营(第三场) J Distance to Work 计算几何求圆与多边形相交面积模板

    链接:https://www.nowcoder.com/acm/contest/141/J来源:牛客网 Eddy has graduated from college. Currently, he i ...

  7. HDU 1255 覆盖的面积 ( 扫描线 + 离散 求矩阵大于k次面积并 )

    覆盖的面积 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Subm ...

  8. hdu 2892 area (圆与多边形交面积)

    Problem - 2892 这道题的做法是以圆心为原点,对多边形进行三角剖分.题目描述中,多边形的可能是顺时针或者是逆时针给出,不过在我的做法里,是用有向面积来计算的,和常见的多边形面积的求法类似, ...

  9. 【C语言】输入圆的半径,求解圆的周长和面积

    公式: C=2πr S=πr² 代码: #include<stdio.h> int main() { float r,PI; PI = 3.14159; printf("请输入圆 ...

随机推荐

  1. Struts2之Action三种接收参数形式与简单的表单验证

    有了前几篇的基础,相信大家对于Struts2已经有了一个很不错的认识,本篇我将为大家介绍一些关于Action接收参数的三种形式,以及简单的表单验证实现,下面进入正题,首先我们一起先来了解一下最基本的A ...

  2. [工具] f.lux – 随时间改变屏幕色温护眼

    f.lux 是一款根据时间变化来改变屏幕色温的软件.让你在深夜也能感受到太阳的温暖,顺便还有助于睡眠. 在 f.lux 里,首先设置一个适合你的变化色温范围,白天的色温控制在 6500K 以下,晚上的 ...

  3. JAVA unicode转换成中文

    /** * * unicode 转换成 中文 * @param theString * @return */ public static String decodeUnicode(String the ...

  4. OC开发_整理笔记——多线程之GCD

    一.进程和线程   二.各种队列! 1.GCD:Grand Central Dispatch 2.串行队列(Serial)      你可以创建任意个数的串行队列,每个队列依次执行添加的任务,一个队列 ...

  5. ubuntu1304无法启动桌面系统的问题和解决

    今天上班,从oracle官网下载个最新的virtual box,安装后重启电脑,进入桌面后竟然没有菜单栏和启动栏了(就是最上边的bar和左边的应用栏),而且所有启动的窗口都没有菜单栏,终端什么的也都没 ...

  6. CvArr* to cv::Mat 转换

    OpenCV中的CvArr*的定义的一个空类型的指针,可以转换为其派生类CvMat和IplImage,那么如何将其转化为cv::Mat呢,其实很简单,只需要一行代码即可: // CvArr *_img ...

  7. easyui---基础组件:window

    window 依赖下面三个组件,就是继承,所以下面的特性和方法 事件都可以用 draggable resizable panel window 和panel不同之处,可以有拖拽移动draggable, ...

  8. HDU-1011 Starship Troopers(树形dp)

    Starship Troopers Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...

  9. 51nod1126 求递推序列的第N项

    求递推序列的第N项 有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的 ...

  10. 搭建linux远程服务器和传输下载文件

    其实,将ubuntu系统设置为服务器很简单,只需要开启ssh服务就可以了.开启了ssh服务以后,其它电脑就可以通过ssh登录你的这台ubuntu服务器.SSH分客户端openssh-client和op ...