Codeforces #195(Div. 2)前两题

A. Vasily the Bear and Triangle
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  • the coordinates of points: x1x2y1y2 are integers. Besides, the following inequation holds: x1 < x2;
  • the triangle formed by point AB and C is rectangular and isosceles ( is right);
  • all points of the favorite rectangle are located inside or on the border of triangle ABC;
  • the area of triangle ABC is as small as possible.

Help the bear, find the required points. It is not so hard to proof that these points are unique.

Input

The first line contains two integers x, y ( - 109 ≤ x, y ≤ 109, x ≠ 0, y ≠ 0).

Output

Print in the single line four integers x1, y1, x2, y2 — the coordinates of the required points.

Sample test(s)
input
10 5
output
0 15 15 0
input
-10 5
output
-15 0 0 15
Note

Codeforces #195(Div. 2)前两题_第1张图片

              

          题目大意:在四个象限给你任意一个点,如图,求出经过这个点的一条线,使得三角形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;
}


B. Vasily the Bear and Fly
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  1. The fly arrived at the coordinate plane at the center of the circle with number  ( is the result of dividing number x by number y, rounded down to an integer).
  2. The fly went along the coordinate plane to the center of the circle number  ( is the remainder after dividing number x by number y). The bear noticed that the fly went from the center of circle v to the center of circle u along the shortest path with all points lying on the border or inside at least one of the 2m circles. After the fly reached the center of circle u, it flew away in an unknown direction.

Help Vasily, count the average distance the fly went along the coordinate plane during each of these m2days.

Input

The first line contains two integers m, R (1 ≤ m ≤ 1051 ≤ R ≤ 10).

Output

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.

Sample test(s)
input
1 1
output
2.0000000000
input
2 2
output
5.4142135624
Note

Codeforces #195(Div. 2)前两题_第2张图片


         题目大意:意思也蛮好懂得,看图就可以明白。可以归结为以下面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<

          昨天晚上出去看电影了,差点回不来了,赶上了末班车。然后又才能进来,充满洗澡,cf.....  

你可能感兴趣的:(Codeforces)