HDU 4720 Naive and Silly Muggles (外切圆心)

来源:互联网 发布:杭州淘宝美工 编辑:程序博客网 时间:2024/05/03 23:26

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 xi and yi (|xi, yi| <= 10), indicating the three wizards' positions. Then a single line with two numbers qx and qy (|qx, qy| <= 10), indicating the muggle's position.

Output
For test case X, output "Case #X: " first, then output "Danger" or "Safe".

Sample Input
30 02 01 21 -0.50 02 01 21 -0.60 03 01 11 -1.5

Sample Output
Case #1: DangerCase #2: SafeCase #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");}}}}


 

import java.awt.Point;import java.io.*;import java.util.*;public class HDU_4720 {BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out), true);StringTokenizer st;int t;double x,y;public static void main(String[] args) throws Exception {new HDU_4720().work();}void work() throws Exception {t = 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 = next();y1 = next();//第二个wizard 的坐标x2 = next();y2 = next();//第三个wizard 的坐标x3 = next();y3 = next();//muggles 坐标x4 = next();y4 = next();//外切园的圆心坐标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");}}}public int nextInt() throws Exception{return Integer.parseInt(bu.readLine());}public double next() throws Exception{while(st==null||!st.hasMoreTokens()){st=new StringTokenizer(bu.readLine());}return Double.parseDouble(st.nextToken());}}


 

 

 

原创粉丝点击