HDOJCuts the cake

Cuts the cake

Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3890    Accepted Submission(s): 2476


Problem Description
Ice cream took a bronze medal in the Beijing match. Liu sir is very very happy. So he buys a cake for them. kiki is a child who likes eating, so the task of cuting cake was given to kiki. kiki is also a mischievous child. She wants to cut the cake in a different way. This is introduced in the figure below.

But there is a difficult problem.which is how to make each preson get equally many cake. kiki is not good at match, so she wants you help her solve this problem.
 

Input
Input contains multiple test cases. Each line is a case. Each case contains only one integer R which is the radius. The input is terminated with a R of 0.
 

Output
For each test case, you should printf two numbers r2 and r1 in a line, accurate up to 3 decimal places, separate them by one space.
 

Sample Input
  
  
10 15 5 25 0
 

Sample Output
  
  
5.774 8.165 8.660 12.247 2.887 4.082 14.434 20.412
 
import java.util.Scanner;

public class Main{
    private static Scanner scanner;
    public static void main(String[] args) {
        scanner = new Scanner(System.in);
        while(scanner.hasNext()){
            int R = scanner.nextInt();
            if(R == 0){
                break;
            }
            double s = Math.PI*R*R;
            double r1 = Math.sqrt((2.0/3*s)/Math.PI);
            double r2 = Math.sqrt((1.0/3*s)/Math.PI);
            System.out.printf("%.3f %.3f",r2,r1);
            System.out.println();
        }
    }
}
//            WA:
//            double r1 = Math.sqrt(2.0/3*R*R);
//            double r2 = Math.sqrt(R*R/3.0);
//            不能直接推导公式(不能把PI约去)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值