close
題目概要:
一隻牛在草原上吃草,牛的鼻子穿過一條固定在兩根柱子之間的繩子,求出牛可以吃多少面積的草。
解題方向:
綠色線會穿過牛的鼻子,所以牛的活動範圍會受到綠色線的影響。
利用橢圓的概念去解題。PI=2*cos^-1(0)(題目提供)
第一個輸入為有多少筆測試資料,接下來每筆測試資料皆會包含2個數字,第一個數字D為2根柱子之間的距離,第二個數字L為繩子長度。
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
*Java | |
*Author:SHEN,ZHI-XUN | |
*Time:2018/7/31 | |
*/ | |
import java.util.Scanner; | |
class main{ | |
public static void main(String args[]){ | |
double PI=2*Math.acos(0); | |
Scanner sc=new Scanner(System.in); | |
int cases=sc.nextInt(); | |
while((cases--)>0){ | |
int D=sc.nextInt(); | |
int L=sc.nextInt(); | |
double a=L/2.0; | |
double c=D/2.0; | |
double b=Math.sqrt(a*a-c*c); | |
System.out.printf("%.3f",a*b*PI); | |
System.out.println(""); | |
} | |
} | |
} |
文章標籤
全站熱搜