Cf #195 (div2) B: Vasily the bear and fly

Source: Internet
Author: User

Http://codeforces.com/contest/336/problem/ B

 

One beautiful day Vasily the bear painted 2MCircles of the same radiusROn a coordinate plane. circles with numbers from1
MHad centers at points (2RAccept-Encoding-R, Limit 0 ),
(4RAccept-Encoding-R, Limit 0 ),
..., (2RmAccept-Encoding-R, Limit 0), respectively. circles with numbers from
MLimit + limit 1 to 2MHad centers at points (2RAccept-Encoding-R, Limit 2R),
(4RAccept-Encoding-R, Limit 2R),
..., (2RmAccept-Encoding-R, Limit 2R), Respectively.

Naturally, the bear painted the circles for a simple experiment with a fly. The experiment continuedM2 days. Each day of the experiment got its own unique number from0
ToM2 audio-extract 1, Volume Sive.

On the day numberIThe following things happened:

  1. The fly arrived at the coordinate plane at the center of the circle with number (
    Is the result of dividing numberXBy numberY, 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 numberXBy numberY). The bear noticed that the fly went from the center of circleVTo the center of circle
    UAlong the shortest path with all points lying on the border or inside at least one of the2MCircles. After the fly reached the center of circleU,
    It flew away in an unknown ction.

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

Input

The first line contains two integersM, Bytes,R(1 digit ≤ DigitMLimit ≤ limit 105, 1 limit ≤ limitRLimit ≤ limit 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 exceed10Upload-Snapshot 6.

Sample test (s) Input
1 1
Output
2.0000000000
Input
2 2
Output
5.4142135624
Note

Figure to the second sample


Question: Give m and R. There are two rows in total, with M circles in each row. The serial number is determined. There are m ^ 2 days in total. Every day. The ending point is

The average distance traveled in m ^ 2 days is required. Note that each distance must be shortest.

 

Train of Thought: Based on the given conditions, we can know that the final route is to traverse all vertices above starting from each lower circle. When the distance is greater than 3, the diagonal lines must be taken twice. At that time, they were stuck here.

 

# Include <stdio. h> # include <string. h> # include <algorithm> # include <math. h> using namespace STD; Double A [100005], s [100005], ans; int main () {int I, m; Double X = SQRT (2.0), R; while (~ Scanf ("% d % lf", & M, & R) {ans = 0; s [0] = 0; A [1] = 2.0 * R; // A [2] = 2.0 * r + x * r when m is 1; // m is 2 with only one diagonal line A [3] = 2.0 * r + 2.0 * x * r; // The vertical distance to be crossed from bottom to top is 3, the shortest for (I = 4; I <= m; I ++) A [I] = A [I-1] + 2 * R; // except for oblique walk, all are straight for (I = 1; I <= m; I ++) s [I] = s [I-1] + A [I]; // Add the walk of all vertices for (I = 1; I <= m; I ++) ans + = (s [I] + s [M-I + 1]-A [1])/m; // Add each walk, because of S restrictions, the symmetry point must be added and the duplicate part is subtracted. * here, we use M as 5 and I as 2. When I = 2, the path should be A2 + A1 + A2 + A3 + A4, that is, A1 + 2 * A2 + A3 + A4 s [2] = A1 + A2, but it cannot be 3, 4, 5, add the symmetry point S [4] = A1 + A2 + A3 + A4 to get the correct path */printf ("%. 10lf \ n ", ANS/M);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.