您的位置:首页 > 编程语言 > Go语言

ural 1084. Goat in the Garden math

2017-06-22 16:40 323 查看


1084. Goat in the Garden

Time limit: 1.0 second

Memory limit: 64 MB

Someone has let a goat in a square kitchen-garden and had bound it to a stake. The stake is driven into the ground in the very midst of the square. The goat is hungry as a hunter and very voracious,
and eats everything that can be reached without leaving the square and tearing off the rope. What area of the kitchen-garden will be ate round?

Input

contains lengths of the garden sides and a cord length in meters (positive integers not exceeding 100, located in one line and separated with a space).

Output

should contain an area of the kitchen-garden (in square meters to within 3 symbols after a decimal point), ate round by the goat.

Sample

inputoutput
10 6

95.091

Problem Author: Irina Danilina
Problem Source: The 3rd high school children programming contest, USU, Yekaterinburg, Russia, March 4, 2001

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) {
new Task().solve();
}
}

class Task {
InputReader in = new InputReader(System.in) ;
PrintWriter out = new PrintWriter(System.out);

void solve() {
double d = in.nextDouble() ;
double r = in.nextDouble() ;
double l = d/2.0 ;
double sum = 0 ;
if(r <= l){
sum = Math.PI * r * r ;
}
else if(r <= Math.sqrt(2.0)*l){
sum = r * r * (Math.PI/4.0 - Math.acos(l/r)) / 2 ;
sum += Math.sqrt(r*r-l*l)*l/2 ;
sum *= 8 ;
}
else{
sum = d * d ;
}
out.printf("%.3f%n" , sum) ;
out.flush();
}

}

class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;

public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = new StringTokenizer("");
}

private void eat(String s) {
tokenizer = new StringTokenizer(s);
}

public String nextLine() {
try {
return reader.readLine();
} catch (Exception e) {
return null;
}
}

public boolean hasNext() {
while (!tokenizer.hasMoreTokens()) {
String s = nextLine();
if (s == null)
return false;
eat(s);
}
return true;
}

public String next() {
hasNext();
return tokenizer.nextToken();
}

public int nextInt() {
return Integer.parseInt(next());
}

public int[] nextInts(int n){
int[] nums = new int
;
for(int i = 0 ; i < n ; i++){
nums[i] = nextInt() ;
}
return nums ;
}

public long nextLong() {
return Long.parseLong(next());
}

public double nextDouble() {
return Double.parseDouble(next());
}

public BigInteger nextBigInteger() {
return new BigInteger(next());
}

}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: