| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
你这题它md扯蛋啊!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1怎么数据类型用double就是对的,用float就是错的?
搞了我半天啊!题中有说明吗?一定要用double???
import java.io.*;
import java.util.StringTokenizer;
import java.math.*;
public class 围成面积{
public final double PI = (double) Math.PI;
public 围成面积() {
}
public void Start() throws Exception {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
String teststring = r.readLine();
int q = 0;
while (!teststring.equals("0 0 0 0")) {
q++;
StringTokenizer st = new StringTokenizer(teststring);
String[] s1 = new String[4];
int i = 0;
while (st.hasMoreTokens()) {
s1[i] = st.nextToken();
i++;
}
double[] f = new double[4];
for (int j = 0; j < 4; j++) {
Double y1 = new Double(s1[j]);
f[j] = y1.doubleValue();
}
double ra = 0f; //所得圆的半径
double s = 0f; //绳子为成总面积
double c = f[1] + f[2] + f[0]; //三角形边场
double cosa = (f[1] * f[1] + f[2] * f[2] - f[0] * f[0]) / (2 * (f[1] * f[2]));
double cosb = (f[0] * f[0] + f[2] * f[2] - f[1] * f[1]) / (2 * (f[0] * f[2]));
double cosc = (f[1] * f[1] + f[0] * f[0] - f[2] * f[2]) / (2 * (f[1] * f[0]));
double St = 0f; //三角形面积
St = 0.5f * f[1] * f[2] * (double) Math.sin(Math.acos(cosa));
double ri = 2 * St / (f[0] + f[1] + f[2]); // 内结缘半径
double ci = 2 * PI * ri;
if (f[3] <= ci) {
ra = f[3] / (2 * PI);
s = PI * ra * ra;
}
else {
ra = 0.5f * (f[3] - c) /
(double) (PI - 1 / Math.tan(0.5 * Math.acos(cosa)) -
1 / Math.tan(0.5 * Math.acos(cosb)) -
1 / Math.tan(0.5 * Math.acos(cosc)));
s = PI * ra * ra + St -
ra *
ra*(double)(1 / Math.tan(0.5 * Math.acos(cosa)) +
1 / Math.tan(0.5 * Math.acos(cosb)) +
1 / Math.tan(0.5 * Math.acos(cosc)));
}
double temp0 = Math.round(100 * s);
s = temp0 / 100;
String ts = "" + s;
int len = ts.length() - 1 - ts.indexOf(".");
ts = "";
for (int a = 2 - len; a > 0; a--) {
ts = ts + "0";
}
System.out.println("Case " + q + ": " + s + ts);
teststring = r.readLine();
}
}
public static void main(String[] args) throws Exception {
围成面积 t1 = new 围成面积();
t1.Start();
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator