ural 1084. Goat in the Garden math
2017-06-22 16:40
323 查看
1084. Goat in the Garden
Time limit: 1.0 secondMemory 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
input | output |
---|---|
10 6 | 95.091 |
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());
}
}
相关文章推荐
- URAL 1786 Sandro's Biography
- URAL1009——DP——K-based Numbers
- 递推DP URAL 1586 Threeprime Numbers
- URAL1224——背包DP+回溯——Gentlemen
- Ural 1353 Milliard Vasya's Function
- URAL1297:Palindrome(后缀数组)
- ural1006 Square Frames
- ural1012 K-based Numbers. Version 2
- URAL1018 Binary Apple Tree
- 思维题 URAL 1409 Two Gangsters
- URAL 1934 spfa算法
- URAL 1942 Attack at the Orbit
- Ural 2018. The Debut Album
- URAL 1319. Hotel
- ural 1038. Spell Checker
- URAL 1780 G - Gray Code 找规律
- ural 1837. Isenbaev's Number bfs
- URAL 1581.Teamwork
- URAL 1203 Scientific Conference dp练习
- ural 1297