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代码:
-
#include<stdio.h>
-
#include<math.h>
-
#define pi 2 * acos(0.0)
-
int main ( ) {
-
int test,cases = 1 ;
-
double rad ;
-
scanf ( "%d", &test ) ;
-
while (test -- ) {
-
scanf ( "%lf", &rad ) ;
-
printf ( "Case %d: %.2lf\n",cases, ( ( ( 2 *rad ) * ( 2 *rad ) ) - (pi *rad *rad ) ) ) ;
-
cases ++ ;
-
}
-
return 0 ;
-
}
-
#include <stdio.h>
-
#define PI 3.1415926535898
-
int main ( )
-
{
-
int t, i ;
-
scanf ( "%d", &t ) ;
-
for (i = 1 ; i <= t ; i ++ )
-
{
-
double r ;
-
scanf ( "%lf", &r ) ;
-
double sc, ss ;
-
sc = PI * r * r ;
-
ss = 4 * r * r ;
-
-
printf ( "Case %d: %.2f\n", i, ss - sc ) ;
-
}
-
return 0 ;
-
}