列表

详情


NC234011. Square Card

描述

Eric is playing a game on an infinite plane.
On the plane, there is a circular area with radius r1 called the Scoring Area. Every time Eric will throw a square card with side length a into the plane, then the card will start rotating around its centre. If at one moment the card is strictly inside the Scoring Area, the current play will be scored.
There is another circular area with radius r2 called the Bonus Area. If the play is scored in the current situation, the square card will continue rotating and if at one moment it is strictly inside the Bonus Area,he will get an extra bonus.
Eric isn’t good at this game, so we can briefly consider that he will throw the card to any postion with an equal probability.
Now Eric wants to know what the ratio of the possibility of being scored and getting the bonus
simultaneously to the possibility of being scored is.
The coordinates of the centre of the Scoring Area are (x_1, y_1).
The coordinates of the centre of the Bonus Area are (x_2, y_2).

输入描述

The first line contains a number , the number of testcases.
For each testcase, there are three lines.
In the first line there are three integers , the radius and the postion of the Scoring Area.
In the second line there are three integers r2,x2,y2(−1000 ≤ x2, y2 ≤ 1000, 0 < r2 ≤ 1000), the radius and the postion of the Bonus Area.
In the third line there is an integer a(0 < a ≤ 1000), the side length of the square card.
It is guaranteed that the Scoring Area is big enough thus there is always a chance for the play to be scored

输出描述

For each test case, output a decimal in one line, the ratio of the possibility of being scored and getting the bonus simultaneously to the possibility of being scored.
Your answer should be rounded to 6 digits after the decimal point.

示例1

输入:

1
5 1 2
3 2 1
1

输出:

0.301720

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++(clang++ 11.0.1) 解法, 执行用时: 2ms, 内存消耗: 452K, 提交时间: 2022-09-23 10:21:10

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
const double pi = acos(-1);
typedef long long ll;

struct point
{
    double x, y;
};

double calc(point a, double r1, point b, double r2)
{
    double dist = sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
    if (r1 + r2 <= dist) return 0;
    
    if (r1 > r2) swap(r1, r2);
    if (r2 - r1 >= dist) return pi * r1 * r1;
    
    double ang1 = acos((r1 * r1 + dist * dist - r2 * r2) / (2.0 * r1 * dist));
    double ang2 = acos((r2 * r2 + dist * dist - r1 * r1) / (2.0 * r2 * dist));
    return ang1 * r1 * r1 + ang2 * r2 * r2 - dist * r1 * sin(ang1);
}
         
int main()
{
    int T;
    scanf("%d", &T);
    
    while (T -- )
    {
        double r1, x1, y1, r2, x2, y2, aa;
        scanf("%lf%lf%lf%lf%lf%lf%lf", &r1, &x1, &y1, &r2, &x2, &y2, &aa);
        if (r1 * r1 - aa * aa / 4 <= 0 || r2 * r2 - aa * aa / 4 <= 0)
        {
            cout << "0.000000" << endl;
            continue;
        }
        
        point a = {x1, y1}, b = {x2, y2};
        double r3 = sqrt(r1 * r1 - aa * aa / 4) - aa / 2, r4 = sqrt(r2 * r2 - aa * aa / 4) - aa / 2;
        double res = calc(a, r3, b, r4);
        printf("%.6lf\n", res / (pi * r3 * r3));
    }
                 
    return 0;
}



C++(g++ 7.5.0) 解法, 执行用时: 2ms, 内存消耗: 296K, 提交时间: 2022-10-04 20:22:37

#include<bits/stdc++.h>
#define P pair<double, double>
using namespace std;
const double pi = acos(-1);
//求两圆相交面积
double area(P a, double r1, P b, double r2)
{
	double d = sqrt((a.first-b.first)*(a.first-b.first) + (a.second-b.second)*(a.second-b.second));
	if(d >= r1+r2) return 0;
	if(r1 > r2) swap(r1,r2);
	if(r2-r1>=d) return pi*r1*r1;
	double ang1 = acos((r1*r1+d*d-r2*r2)/(2*r1*d));
	double ang2 = acos((r2*r2+d*d-r1*r1)/(2*r2*d));
	return ang1*r1*r1 + ang2*r2*r2 - r1*d*sin(ang1);
}

int main()
{
    int T;  
    cin>>T;
    while(T--)
    {
        double ra,xa,ya,rb,xb,yb,a;
		cin>>ra>>xa>>ya>>rb>>xb>>yb>>a;
		if(rb*rb-a*a/4 < 0){ cout<<"0.000000"<<endl; continue; }
        P ap=P(xa,ya), bp=P(xb,yb);
		double r1 = sqrt(ra*ra-a*a/4)-a/2, r2 = sqrt(rb*rb-a*a/4)-a/2;
		double res = area(ap, r1, bp, r2);
		printf("%.6f\n", res/(pi*r1*r1));
    }
    return 0;
}

上一题