Is This Integration?

Is This Integration?

时间: 1ms        内存:64M

描述:

The image below shows a square ABCD, where AB = BC = CD = DA = a. Four arcs are drawn taking the four vertexes A, B, C, D as centers and a as the radius. The arc that is drawn taking A as center starts at neighboring vertex B and ends at neighboring vertex D. All other arcs are drawn in a similar fashion. Regions of three different shapes are created in this fashion. You must determine the total area of these different shaped regions.

输入:

Each line of the input file contains a floating-point number a indicating the side length of the square, where 0 <= a<= 10, 000.0. Input is terminated by end of file.

输出:

For each test case, output on a single line the area of the different region types in the image above. Each floating point number should be printed with three digits after the decimal point. The first number of each case will denote the area of the striped region, the second number will denote the total area of the dotted regions, and the third number will denote the rest of the area.

示例输入:

0.1
0.2
0.3

示例输出:

0.003 0.005 0.002
0.013 0.020 0.007
0.028 0.046 0.016

提示:

参考答案(内存最优[748]):

#include <stdio.h>
#include <math.h>
#define pi 3.141592653589793
//受不了 需要这么高精度的pi
int main(){
	double a;
	while(scanf("%lf",&a)==1){
		double x=a*a*(1+pi/3-sqrt(3));
		double y=a*a*(2*sqrt(3)+pi/3-4);
		double z=a*a*(4-sqrt(3)-2*pi/3);
		printf("%.3lf %.3lf %.3lf\n",x,y,z);
	}
	return 0;
}

参考答案(时间最优[0]):

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
using namespace std;
int main()
{
    float a,b,c;
    cin>>a>>b>>c;
    cout<<"0.003 0.005 0.002\n0.013 0.020 0.007\n0.028 0.046 0.016\n";
    return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注