1. 程式人生 > >Hard problem(兩圓相交)

Hard problem(兩圓相交)

Hard problem
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 843    Accepted Submission(s): 527
Problem Description
cjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school students. It is too difficult for cjj. Can you solve it?


Give you the side length of the square L, you need to calculate the shaded area in the picture.


The full circle is the inscribed circle of the square, and the center of two quarter circle is the vertex of square, and its radius is the length of the square.
 
Input

The first line contains a integer T(1<=T<=10000), means the number of the test case. Each case contains one line with integer l(1<=l<=10000).

Output
For each test case, print one line, the shade area in the picture. The answer is round to two digit.

Sample Input1 1
Sample Output0.29

(area_S表示S的面積)

以正方形左下角為座標軸原點,分別以正方形下邊、左邊為X軸,Y軸,以左上角為圓心(0,l)半徑為l作圓S1,以右下角(l,0)為圓心半徑為l作圓S2,正方形內切圓是以(l/2,l/2)為圓心,l/2為半徑的圓S。

思路:求出圓S與圓S1相交部分面積area1和圓S與圓S2的相交面積area2,設S中空白部分面積為X,有area1+area2-X=area_S;求出X,用area_S-X即得陰影部分面積。area1與area2是相等的,所以用求出一個即可。

只要敲出兩圓相交面積模板就行了:

#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;

#define pi acos(-1.0)

typedef struct node
{
	double x;
	double y;
}point;
//兩圓相交求陰影面積
double AREA(point a, double r1, point b, double r2)
{
	double d = sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y));
	if (d >= r1+r2)
		return 0;
	if (r1>r2)
	{
		double tmp = r1;
		r1 = r2;
		r2 = tmp;
	}
	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;
    scanf("%d",&t);
    while(t--)
    {
        int n;
        scanf("%d",&n);
        point a, b;
        a.x=n*1.0/2, a.y=n*1.0/2;
	    b.x=n*1.0, b.y=0.0;
	   double result = AREA(a, n*1.0/2.0, b, n*1.0);
	   printf("%.2lf\n",2.0*pi*(n*1.0/2.0)*(n*1.0/2.0)-2.0*result);
    }
	return 0;
}

相關推薦

Hard problem相交

Hard problemTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 843    Accepted Submis

hdu 5120 Intersection相交面積模板

Intersection 題目連結: 解題思路: 在紙上畫畫圖,不難發現,根據容斥定理:所要求的面積為兩外環的交集(ans1)-外環和內環的交集(ans2*2,對稱)+兩內環的 交集(多減去的部分,

幾何問題相交的面積

編輯 刪除 Description     There are two circles in the plane (shown in the below picture), there is a common area between the two circle

計算幾何專題計算相交面積

There are two circles in the plane (shown in the below picture), there is a common area between the

【CodeForces - 706C】Hard problemdp,字典序

題幹: Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given&nbs

「專題訓練」Hard problemCodeforces Round #367 Div. 2 C

題意與分析 題意:給出\(n\)個字串,可以反轉任意串,反轉每個串都有其對應的花費\(c_i\)。經過操作後是否能滿足字串\(\forall i \in [1,n] \text{且} i \in R_+, str[i]\ge str[i-1]\),若能輸出最小花費,否則輸出-1。 分析:經過各種字串dp血虐

ZCMU 1795: wjw的hard problemdfs+思維

ZCMU 1795: wjw的hard problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 69  Solved: 21 [Submit][Status][Web Board] Description ly最

【ZCMU1795】wjw的hard problemdfs

題目連結 1795: wjw的hard problem Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 70  Solved: 22 [Submit][Status][Web Board] Description

706C】Hard problemdp,字典序

題幹: Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is g

ZOJ 3825 Garden and Sprinklers直線與相交

暫存【不好意思,TLE了】 #include <iostream> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <

HDU 5858 Hard problem計算幾何

Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) Problem Description cjj is fun with math prob

NP-Hard Problemcf#360

C. NP-Hard Problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard

HDU 5858 Hard problem計算幾何【較難】【多校聯合8.18】

解題思路: 看懂這個圖,這個題就能A掉了。 下面是AC程式碼: #include<cstdio> #include<cstring> #include<c

5858 Hard problem 非常詳細的解答

cjj is fun with math problem. One day he found a Olympic Mathematics problem for primary school

CodeForces 706 C. Hard problemdp

Description 給出n個字串,翻轉第i個串需要一個代價c[i],問使得這n個字串保持升序所需的最小代價 Input 第一行一整數n表示字串數量,之後n個整數c[i]表示翻轉第i個串所需花費

Codeforces Round #367 (Div. 2) C. Hard problem dp

Note In the second sample one has to reverse string 2 or string 3. To amount of energy required to reverse the string 3 is smaller. In the third sample

FZU 2214 Knapsack problem 01背包

knapsack i+1 int name cst 轉化 break urn tdi 題意:給你n種物品,每種只有一個,第i種物品的價值為Vi,重量為Wi,把這些物品放入一個重量限制為B的背包中,使得背包內的物品在重量不超過B的前提下,價值盡量大,輸出最大價值 1 <

springMVC --全局異常處理種方式

nal font method mil -h util 一個 fail space 首先看springMVC的配置文件: <!-- 全局異常配置 start --> <bean id="exceptionResolv

LeetCode 1. Two Sum 數之和

ret desc rip twosum 關鍵點 earch pub ++ num Given an array of integers, return indices of the two numbers such that they add up to a specif

eclipse批量替換,修改變量名或單詞種方法

.com 雙擊 方框 批量 ref lac cnblogs height ima 第一種(常用):   ①如圖:雙擊選中變量名id,右鍵選擇Refactor中的Rename   ②之後如下圖所示,紅箭頭的帶有方框的就是選中修改的變量名,此時修改提示框的內容,後面帶方框的也