HDU 4720 Naive and Silly Muggles(外接円心)

3053 ワード

Naive and Silly Muggles
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 228 Accepted Submission(s): 163
Problem Description
Three wizards are doing a experiment. To avoid from bothering, a special magic is set around them. The magic forms a circle, which covers those three wizards, in other words, all of them are inside or on the border of the circle. And due to save the magic power, circle's area should as smaller as it could be.
Naive and silly "muggles"(who have no talents in magic) should absolutely not get into the circle, nor even on its border, or they will be in danger.
Given the position of a muggle, is he safe, or in serious danger?
 
 
Input
The first line has a number T (T <= 10) , indicating the number of test cases.
For each test case there are four lines. Three lines come each with two integers x
i and y
i (|x
i, y
i| <= 10), indicating the three wizards' positions. Then a single line with two numbers q
x and q
y (|q
x, q
y| <= 10), indicating the muggle's position.
 
 
Output
For test case X, output "Case #X: "first, then output "Danger"or "Safe".
 
 
Sample Input
3 0 0 2 0 1 2 1 -0.5 0 0 2 0 1 2 1 -0.6 0 0 3 0 1 1 1 -1.5
 
 
Sample Output
Case #1: Danger Case #2: Safe Case #3: Safe
 
 
Source
2013 ACM/ICPC Asia Regional Online —— Warmup2
 
外接円心座標
x=(x1+x2+x3)/3;
y=(y1+y2+y3)/3;
 
import java.awt.Point;

import java.io.*;

import java.util.*;



public class Main {

	BufferedReader bu;

	PrintWriter pw;

	int t;

	double x,y;

	public static void main(String[] args) throws Exception {

		new Main().work();

	}



	void work() throws Exception {

		Scanner sc=new Scanner(new InputStreamReader(System.in));

		pw = new PrintWriter(new OutputStreamWriter(System.out), true);

		t = sc.nextInt();

		for (int p = 1; p <= t; p++) {

			pw.print("Case #" + p + ": ");

			double x1, y1;

			double x2, y2;

			double x3, y3;

			double x4, y4;

			//   wizard    

			x1 = sc.nextDouble();

			y1 = sc.nextDouble();

			//   wizard    

			x2 = sc.nextDouble();

			y2 = sc.nextDouble();

			//   wizard    

			x3 = sc.nextDouble();

			y3 = sc.nextDouble();

			//muggles   

			x4 = sc.nextDouble();

			y4 = sc.nextDouble();

			//        

			x=(x1+x2+x3)/3;

			y=(y1+y2+y3)/3;

			//  

			double r=Math.sqrt((x1-x)*(x1-x)+(y1-y)*(y1-y));

			//muggles      

			double d=Math.sqrt((x4-x)*(x4-x)+(y4-y)*(y4-y));

			

			if(d>r){

				pw.println("Safe");

			}

			else{

				pw.println("Danger");

			}

		}

	}

}