CodeForces Round 195 Div2

A. Vasily the Bear and Triangle
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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: x1, x2, y1, y2 are integers. Besides, the following inequation holds: x1 < x2;
the triangle formed by point A, B 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

#include<stdio.h>
int main()
{
__int64 x,y,x1,x2,y1,y2;
scanf("%I64d%I64d",&x,&y);
if (x> && y>)
{
x1=;
y1=x+y;
x2=x+y;
y2=;
}
else if (x< && y>)
{
x1=x-y;
y1=;
x2=;
y2=y-x;
}
else if (x< && y<)
{
x1=(x+y);
y1=;
x2=;
y2=(x+y);
}
else
{
x1=;
y1=y-x;
x2=x-y;
y2=;
}
printf("%I64d %I64d %I64d %I64d\n",x1,y1,x2,y2);
return ;
}

B. Vasily the Bear and Fly
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard 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 for m2 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:

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).
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 m2 days.

Input
The first line contains two integers m, R (1 ≤ m ≤ 105, 1 ≤ 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

#include<math.h>
#include<stdio.h>
double dis(int x,double R)
{
if (x==) return *R+sqrt(2.0)*R;
return (*x-)*R+sqrt(8.0)*R;
}
int main()
{
double m,R;
int i;
scanf("%lf%lf",&m,&R);
double tot=m**R;
for (i=;i<m;i++) tot+=dis(i,R)*(m-i)*;
double ave=tot/(m*m*1.0);
printf("%.10lf\n",ave);
return ;
}
上一篇:NIOS II 之串口学习


下一篇:LightOJ 1197 Help Hanzo 素数筛