zoukankan      html  css  js  c++  java
  • LightOJ 1118

    1118 - Incredible Molecules
    Time Limit: 0.5 second(s) Memory Limit: 32 MB

    In the biological lab, you were examining some of the molecules. You got some interesting behavior about some of the molecules. There are some circular molecules, when two of them collide, they overlap with each other, and it's hard to find that which one is over the other one.

    Given two molecules as circles, you have to find the common area of the given molecules that is shaded in the picture.

     

    Overlapping Molecules

    Input

    Input starts with an integer T (≤ 12), denoting the number of test cases.

    Each case contains six integers x1, y1, r1 and x2, y2, r2. Where (x1, y1) is the center of the first molecule and r1 is the radius and (x2, y2) is the center of the second molecule and r2 is the radius. Both the radiuses are positive. No integer will contain more than 3 digits.

    Output

    For each test case, print the case number and the common area of the given molecules. Errors less than 10-6 will be ignored.

    Sample Input

    Output for Sample Input

    3

    0 0 10 15 0 10

    -10 -10 5 0 -10 10

    100 100 20 100 110 20

    Case 1: 45.3311753978

    Case 2: 35.07666099

    Case 3: 860.84369

    http://lightoj.com/volume_showproblem.php?problem=1118

    很简单,作为模板了

     1 /* ***********************************************
     2 Author        :kuangbin
     3 Created Time  :2013-10-15 18:56:20
     4 File Name     :E:2013ACM专题强化训练计算几何LightOJ1118.cpp
     5 ************************************************ */
     6 
     7 #include <stdio.h>
     8 #include <string.h>
     9 #include <iostream>
    10 #include <algorithm>
    11 #include <vector>
    12 #include <queue>
    13 #include <set>
    14 #include <map>
    15 #include <string>
    16 #include <math.h>
    17 #include <stdlib.h>
    18 #include <time.h>
    19 using namespace std;
    20 
    21 const double eps = 1e-8;
    22 const double PI = acos(-1.0);
    23 struct Point
    24 {
    25     double x,y;
    26     void input()
    27     {
    28         scanf("%lf%lf",&x,&y);
    29     }
    30 };
    31 double dist(Point a,Point b)
    32 {
    33     return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    34 }
    35 //两个圆的公共部分面积
    36 double Area_of_overlap(Point c1,double r1,Point c2,double r2)
    37 {
    38     double d = dist(c1,c2);
    39     if(r1 + r2 < d + eps)return 0;
    40     if(d < fabs(r1 - r2) + eps)
    41     {
    42         double r = min(r1,r2);
    43         return PI*r*r;
    44     }
    45     double x = (d*d + r1*r1 - r2*r2)/(2*d);
    46     double t1 = acos(x / r1);
    47     double t2 = acos((d - x)/r2);
    48     return r1*r1*t1 + r2*r2*t2 - d*r1*sin(t1);
    49 }
    50 
    51 int main()
    52 {
    53     //freopen("in.txt","r",stdin);
    54     //freopen("out.txt","w",stdout);
    55     Point c1,c2;
    56     double r1,r2;
    57     int T;
    58     scanf("%d",&T);
    59     int iCase = 0;
    60     while(T--)
    61     {
    62         iCase ++;
    63         c1.input();
    64         scanf("%lf",&r1);
    65         c2.input();
    66         scanf("%lf",&r2);
    67         printf("Case %d: %.6lf
    ",iCase,Area_of_overlap(c1,r1,c2,r2));
    68     }
    69     return 0;
    70 }
  • 相关阅读:
    webpack的入门实践,看这篇就够了
    vue系列教程-15vuex的使用
    vue系列教程-14axios的使用
    vue系列教程-13vuecli初体验
    vue系列教程-12vue单文件组件开发
    vue系列教程-11vuerouter路由
    vue系列教程-10vue过滤器和自定义指令
    vue系列教程-09vue组件
    Spring Redis开启事务支持错误用法导致服务不可用
    MySQL主从数据库配置与原理
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3370886.html
Copyright © 2011-2022 走看看