D e s c r i p t i o n Description Description
又到暑假啦,
C
o
n
a
n
,
A
y
u
m
i
,
M
i
t
s
u
h
i
k
o
,
G
e
n
t
a
Conan, Ayumi, Mitsuhiko, Genta
Conan,Ayumi,Mitsuhiko,Genta一起到
H
a
k
a
s
e
Hakase
Hakase家愉快玩耍(然而你却不行……)。
A
y
u
m
i
,
M
i
t
s
u
h
i
k
o
,
G
e
n
t
a
Ayumi, Mitsuhiko, Genta
Ayumi,Mitsuhiko,Genta依次开始画正方形(显然Ai是不会参加这个活动的),一人一笔,画完一个,以上一个正方形四边中点为顶点接着画啊画啊画啊……最后一共画了
k
k
k个正方形。最终他们想知道自己各画了多长。
I n p u t Input Input
输入一行包含两个整数 N , K N,K N,K,分别表示第一个正方形的边长,正方形个数。
O u t p u t Output Output
输出一行,三个实数,分别表示 A y u m i , M i t s u h i k o , G e n t a Ayumi, Mitsuhiko, Genta Ayumi,Mitsuhiko,Genta画的长度,答案保留3位小数。
S a m p l e I n p u t Sample Input SampleInput
100 2
S a m p l e O u t p u t Sample Output SampleOutput
270.711 241.421 170.711
T r a i n Train Train O f Of Of T h o u g h t Thought Thought
首先用勾股定理求出正方形的边,如图:
从图中我们可以看出
a
=
50
,
b
=
50
a=50,b=50
a=50,b=50,
所以
c
=
a
2
+
b
2
=
2
∗
a
2
=
2
∗
5
0
2
c=\sqrt{a^2+b^2}=\sqrt{2*a^2}=\sqrt{2*50^2}
c=a2+b2=2∗a2=2∗502
再一个个加进去就好了
C o d e Code Code
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
double a[5],l;//必须要用double,float过不了
bool b[5];
int k,n;
int main()
{
scanf("%d%d",&n,&k);
for(int i=1; i<=3; ++i)
a[i]=(double)a[i]+n;
a[1]=(double)a[1]+n; b[1]=true;
--k; l=n;
while (k>=1)
{
l=sqrt(2*(l/2)*(l/2));
int pp=1,p=0;
while (p<=3)
{
if (b[1] && b[2] && b[3]) b[1]=b[2]=b[3]=false;//刷新
if (!b[pp]) a[pp]=(double)l+a[pp],p++,b[pp]=1;//标记是否加过
pp++;
if(pp==4) pp=1;
}
--k;
}
for (int i=1; i<=3; ++i)
printf("%.3lf ",a[i]);//输出
return 0;
}