Vasily the bear has a favorite rectangle, it has one vertex at point (0, 0), and the opposite vertex at point (x, y). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes.
Vasya also loves triangles, if the triangles have one vertex at point B = (0, 0). That's why today he asks you to find two points A = (x1, y1) and C = (x2, y2), such that the following conditions hold:
Help the bear, find the required points. It is not so hard to proof that these points are unique.
The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).
Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.
10 5
0 15 15 0
-10 5
-15 0 0 15
题目大意:在四个象限给你任意一个点,如图,求出经过这个点的一条线,使得三角形ABC的面积最小。
解题思路:最开始20分钟一直在纸上模拟它说的什么意思,最后一翻才看见了图。瞬间无语了。还是经验不够啊。开始看到这个,就直接推公式。设这个点在第一象限(a,b)...设曲线为y=-k(x-a)+b.则有(0,ak+b),(b/k+a,0)然后直接求面积s=1/2*(ak+b)*(b/k+a). 2s=a^2+b^2+b^2/k+a^2*k>=a^2+b^2+2ab=(a+b)^2. 对勾函数取得最小值之直接是b^2/k=a^2*k得k=b/a. 但是这样求得却不对。。。。 到最后无奈只得往回推一步,最小面积是(a+b)^2.直接把两个点都设置成a+b即可。然后分四个象限分类,详解见代码.
题目地址:A. Vasily the Bear and Triangle
AC代码:
#include
#include
#include
#include
#include
using namespace std;
int main()
{
int a,b;
while(~scanf("%d%d",&a,&b))
{
int c=abs(a)+abs(b);
if(a<0&&b>0)
printf("%d 0 0 %d\n",-c,c);
else if(a>0&&b>0)
printf("0 %d %d 0\n",c,c);
else if(a<0&&b<0)
printf("%d 0 0 %d\n",-c,-c);
else
printf("0 %d %d 0\n",-c,c);
}
return 0;
}
One beautiful day Vasily the bear painted 2m circles of the same radius R on a coordinate plane. Circles with numbers from 1 to m had centers at points (2R - R, 0), (4R - R, 0), ..., (2Rm - R, 0), respectively. Circles with numbers from m + 1 to 2m had centers at points (2R - R, 2R), (4R - R, 2R),..., (2Rm - R, 2R), respectively.
Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continued form2 days. Each day of the experiment got its own unique number from 0 to m2 - 1, inclusive.
On the day number i the following things happened:
Help Vasily, count the average distance the fly went along the coordinate plane during each of these m2days.
The first line contains two integers m, R (1 ≤ m ≤ 105, 1 ≤ R ≤ 10).
In a single line print a single real number — the answer to the problem. The answer will be considered correct if its absolute or relative error doesn't exceed 10 - 6.
1 1
2.0000000000
2 2
5.4142135624
题目大意:意思也蛮好懂得,看图就可以明白。可以归结为以下面m个圆心为起点,以上面m个圆心为终点。
解题思路:开始思路错误,而且用的是int.主要是比如说下面3到上面5这样的点,这样应该是2+2sqrt(2),而自己写成了4+sqrt(2)。思路正确,把公式一推出来就可以了。我的思路是这样先统计直接下面对上面竖直的点,然后+从1到i-1的+从i+1到m的。具体规律见代码。
题目地址:B. Vasily the Bear and Fly
AC代码:
#include
#include
#include
#include
#include
using namespace std;
double t=sqrt(2.0);
int main()
{
__int64 m,r,i;
while(~scanf("%I64d%I64d",&m,&r))
{
double res=2*m; //i与m+i竖着的统计起来
for(i=1;i<=m;i++)
{
if(m-i>=1)
{
res+=(m-i)*(m-i-1);
res+=2*(m-i-1)*t;
res+=2.0+t; //最近的一个点
}
if(i>=2)
{
res+=(i-1)*(i-2);
res+=2*(i-2)*t;
res+=2.0+t; //最近的一个点
}
}
res*=r;
res=res/double(m);
res=res/double(m);
printf("%.8f\n",res);
}
/*int p=100000;
cout<