首页 > 专题系列 > Java解POJ > POJ 2242 The Circumference of the Circle [解题报告] Java
2013
11-10

POJ 2242 The Circumference of the Circle [解题报告] Java

The Circumference of the Circle

问题描述 :

To calculate the circumference of a circle seems to be an easy task – provided you know its diameter. But what if you don’t?

You are given the cartesian coordinates of three non-collinear points in the plane.

Your job is to calculate the circumference of the unique circle that intersects all three points.

输入:

The input will contain one or more test cases. Each test case consists of one line containing six real numbers x1,y1, x2,y2,x3,y3, representing the coordinates of the three points. The diameter of the circle determined by the three points will never exceed a million. Input is terminated by end of file.

输出:

For each test case, print one line containing one real number telling the circumference of the circle determined by the three points. The circumference is to be printed accurately rounded to two decimals. The value of pi is approximately 3.141592653589793.

样例输入:

0.0 -0.5 0.5 0.0 0.0 0.5
0.0 0.0 0.0 1.0 1.0 1.0
5.0 5.0 5.0 7.0 4.0 6.0
0.0 0.0 -1.0 7.0 7.0 7.0
50.0 50.0 50.0 70.0 40.0 60.0
0.0 0.0 10.0 0.0 20.0 1.0
0.0 -500000.0 500000.0 0.0 0.0 500000.0

样例输出:

3.14
4.44
6.28
31.42
62.83
632.24
3141592.65

解题代码:

//* @author popop0p0popo
import java.util.*;
import java.io.*;

public class Main{
 public static void main(String[] args){
  Scanner scanner=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
	double[] x,y;
	double k1,k2,b1,b2,ox,oy;
	double r;
	while (scanner.hasNext()){
		x=new double[3];
		y=new double[3];
		for (int i=0;i< 3 ;i++ ){
			x[i]=scanner.nextDouble();
			y[i]=scanner.nextDouble();
		}
		if (y[0]==y[1]){
			double t=y[0];
			y[0]=y[2];
			y[2]=t;
			t=x[0];
			x[0]=x[2];
			x[2]=t;
		}
		if (y[0]==y[2]){
			double t=y[0];
			y[0]=y[1];
			y[1]=t;
			t=x[0];
			x[0]=x[1];
			x[1]=t;
		}
	k1=0-(x[0]-x[1])/(y[0]-y[1]);
	b1=(y[0]+y[1])/2-k1*(x[0]+x[1])/2;
	k2=0-(x[0]-x[2])/(y[0]-y[2]);
	b2=(y[0]+y[2])/2-k2*(x[0]+x[2])/2;
	ox=(b2-b1)/(k1-k2);
	oy=k1*ox+b1;
	r=Math.sqrt((ox-x[0])*(ox-x[0])+(oy-y[0])*(oy-y[0]));
	System.out.println(Math.round(2*3.141592653589793*r*100.0)/100.0);
	}
}
}

  1. 博主您好,这是一个内容十分优秀的博客,而且界面也非常漂亮。但是为什么博客的响应速度这么慢,虽然博客的主机在国外,但是我开启VPN还是经常响应很久,再者打开某些页面经常会出现数据库连接出错的提示

  2. 可以参考算法导论中的时间戳。就是结束访问时间,最后结束的顶点肯定是入度为0的顶点,因为DFS要回溯

  3. 第一句可以忽略不计了吧。从第二句开始分析,说明这个花色下的所有牌都会在其它里面出现,那么还剩下♠️和♦️。第三句,可以排除2和7,因为在两种花色里有。现在是第四句,因为♠️还剩下多个,只有是♦️B才能知道答案。

  4. 在方法1里面:

    //遍历所有的边,计算入度
    for(int i=0; i<V; i++)
    {
    degree = 0;
    for (j = adj .begin(); j != adj .end(); ++j)
    {
    degree[*j]++;
    }
    }

    为什么每遍历一条链表,要首先将每个链表头的顶点的入度置为0呢?
    比如顶点5,若在顶点1、2、3、4的链表中出现过顶点5,那么要增加顶点5的入度,但是在遍历顶点5的链表时,又将顶点5的入度置为0了,那之前的从顶点1234到顶点5的边不是都没了吗?