Light OJ 1022

A circle is placed perfectly into a square. The termperfectly placed means that each side of the square is touched by the circle,but the circle doesn't have any overlapping part with the square. See thepicture below.

Now you are given the radius of the circle. You have to findthe area of the shaded region (blue part). Assume thatpi = 2 * acos (0.0)(acos means cos inverse).

Input

Input starts with an integer T (≤ 1000),denoting the number of test cases.

Each case contains a floating point number r (0 < r ≤1000) denoting the radius of the circle. And you can assume thatrcontains at most four digits after the decimal point.

Output

For each case, print the case number and the shaded arearounded to two places after the decimal point.

Sample Input

Output for Sample Input

3

20

30.091

87.0921

Case 1: 343.36

Case 2: 777.26

Case 3: 6511.05


一道很简单的求阴影部分面积的题,不过一开始不知道Pi如何取,来了个3.1415;提交WA

看了评论再仔细以看题目发现可以这样:

#include<stdio.h>
#include<math.h>
int main()
{    
    int n,i;
    double m,s;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lf",&m);
        s=m*m*(4-2*acos(0.0));

        printf("Case %d: %.2lf\n",i,s);
    }
    return 0;
}


题末有个小提示:This problem doesn't have special judge. So, be carefulabout precision problems. Better to add a small value to your result to avoidprecision problems. For example, add10-9 to your result.

没看懂什么意思。。。。

Fuck ,rank竟然是216!桑心啊

Rank first代码:

  1. #include<stdio.h>
  2. #include<math.h>
  3. #define pi  2 * acos(0.0)
  4. int main ( ) {
  5.     int test,cases = 1 ;
  6.     double rad ;
  7.     scanf ( "%d", &test ) ;
  8.     while (test -- ) {
  9.         scanf ( "%lf", &rad ) ;
  10.         printf ( "Case %d: %.2lf\n",cases, ( ( ( 2 *rad ) * ( 2 *rad ) ) - (pi *rad *rad ) ) ) ;
  11.         cases ++ ;
  12.     }
  13.     return 0 ;
  14. }
尼玛的心理不平衡了!!这种代码也排第一:
  1. #include <stdio.h>
  2. #define PI 3.1415926535898
  3. int main ( )
  4. {
  5.     int t, i ;
  6.     scanf ( "%d", &t ) ;
  7.     for (i = 1 ; i <= t ; i ++ )
  8.     {
  9.         double r ;
  10.         scanf ( "%lf", &r ) ;
  11.         double sc, ss ;
  12.         sc = PI * r * r ;
  13.         ss = 4 * r * r ;
  14.  
  15.         printf ( "Case %d: %.2f\n", i, ss - sc ) ;
  16.     }
  17.     return 0 ;
  18. }


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值