Pages

Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

1/19/2014

UVA 113 Solution

import java.math.BigInteger;
import java.util.Scanner;

class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
//BigInteger p = new BigInteger("4357186184021382204544");

double x =sc.nextDouble();
//if (x==0.0) break;
double y = sc.nextDouble();
//System.out.println(Math.log10(y));
//System.out.println(x);
System.out.println(Math.round(Math.pow(10.0, (Math.log10(y)/x))));
}

}

}

UVA 10079 Pizza Cutting Solution

import java.util.Scanner;

class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while (sc.hasNext()) {
long no = sc.nextLong();
if (no<0l) break;
System.out.println(1+((no*(no+1l))/2l));

}
}

}

UVA 10678 The Grazing Cow Solution

import java.math.BigInteger;
import java.util.Scanner;
class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
StringBuffer br = new StringBuffer("");

int tc = sc.nextInt();

for (int i = 1; i<= tc;i++) {
double d= sc.nextDouble();
double l = sc.nextDouble();
double a = Math.sqrt(.25 * (l*l - d*d));
double b = l/2.0;

double area = Math.PI*a*b*1000;
System.out.printf("%.3f\n",Math.round(area)/1000.0);
}
}

}

UVA 10297 Beavergnaw Solution

import java.math.BigInteger;
import java.util.Scanner;
class Main {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
StringBuffer br = new StringBuffer("");

while(true) {
double D = sc.nextDouble();
double Vch = sc.nextDouble();
if (D==0.0 && Vch==0.0) break;

double res = (6.0/Math.PI) * (((Math.PI * D*D*D / 4.0) - Vch)) - (0.5 *D*D*D);
//System.out.println(res);
res = Math.pow(res,( 1.0/3.0));
//res = Math.round(res*1000)/1000.0;
System.out.printf("%.3f\n",res);

}
}

}