zoukankan      html  css  js  c++  java
  • K. Wolf and sheep

    A sheep lives on an infinite field. The sheep wants to eat some grass. Grass only exists in one place. That place is a circle defined by a center point (Gx, Gy) and a radius Gr.

    The sheep would gladly eat all the grass. But if you read the title of this task you noticed that there is also a wolf on that field. The wolf wants to eat the sheep, but we don't want that to happen.

    The wolf is tied to a pole at position (Wx, Wy) with a rope of length Wr.

    Find the area of grass that the sheep can eat without being eaten by the wolf. We can assume that the sheep starts in a safe location.

    Input

    The first line contains the number of test cases T (1 ≤ T ≤ 10000).

    Each test case consists of 2 lines. The first line contains integers Gx, Gy and Gr. The second line contains integers Wx, Wy and Wr. ( - 105 ≤ Gx, Gy, Wx, Wy ≤ 105, 1 ≤ Gr, Wr ≤ 105)

    Output

    For each test case output one line containing “Case #tc: A”, where tc is the number of the test case (starting from 1) and A is the area of grass that the sheep can eat safely with a maximum absolute or relative error of 10 - 6.

    Examples
    Input
    2
    0 0 5
    0 10 5
    0 0 5
    5 0 5
    Output
    Case #1: 78.53981634
    Case #2: 47.83057387

    有一头羊和一头狼,分别有一个园的范围,在狼会吃羊,求羊最大可以吃草的范围是多大。

    1.当两园相离或外切时,答案就是羊所在的面积

    2.当狼的范围包含羊时,答案就是0

    3.当羊的范围包含狼是,答案就是羊的面积减去狼的面积

    4.当两园相交时,答案就是羊的面积减去重合的面积

    主要是相交的面积难算,当相交时,重合面积是两个扇形面积之和减去平行四边形的面积。可以用余弦定理算出两个扇形的弧度,这个扇形面积和平行四边形的面积就出来了。

     1 #include <iostream>
     2 #include <stdio.h>
     3 #include <string.h>
     4 #include <algorithm>
     5 #include <math.h>
     6 #include <vector>
     7 #include <set>
     8 #include <map>
     9 #define ll long long
    10 #define INF 0x3f3f3f3f
    11 using namespace std;
    12 const int N = 110;
    13 double dis(double x1, double y1, double x2, double y2) {
    14     return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
    15 }
    16 int main() {
    17     int t, k = 1;
    18     scanf("%d", &t);
    19     double pi = acos(-1);
    20     while(t--) {
    21         double gx, gy, gr, wx, wy, wr;
    22         cin >> gx >> gy >> gr;
    23         cin >> wx >> wy >> wr;
    24         double dd = dis(gx, gy, wx, wy);
    25         if(dd >= (gr+wr)) {
    26             printf("Case #%d: %.8lf
    ",k++,pi*gr*gr);
    27         } else if(dd + wr <= gr ){
    28             printf("Case #%d: %.8lf
    ",k++,pi*(gr*gr - wr*wr));
    29         } else if(dd + gr <= wr) {
    30             printf("Case #%d: 0.00000000
    ",k++);
    31         } else {
    32             double a1 = acos((gr*gr + dd*dd - wr*wr) / (2*gr*dd));
    33             double a2 = acos((wr*wr + dd*dd - gr*gr) / (2*wr*dd));
    34             double area1 = (sin(a1*2)*gr*gr+sin(a2*2)*wr*wr)/2;
    35             double area2 = gr*gr*a1 + wr*wr*a2;
    36             printf("Case #%d: %.8lf
    ",k++,pi*gr*gr-(area2-area1));
    37         }
    38     }
    39     return 0;
    40 }
  • 相关阅读:
    谈谈最近求职的那些事
    新的一年你该如何起飞
    JavaScript原型链和instanceof运算符的暧昧关系
    (译)详解javascript立即执行函数表达式(IIFE)
    一道有意思的笔试题引发的对于new操作符的思考
    javascript中prototype、constructor以及__proto__之间的三角关系
    这10道javascript笔试题你都会么
    汤姆大叔的6道javascript编程题题解
    打字机游戏Ⅱ之手速pk
    css3实践之摩天轮式图片轮播+3D正方体+3D标签云(perspective、transform-style、perspective-origin)
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/7614571.html
Copyright © 2011-2022 走看看