编程介的小学生 2017-03-01 12:07 采纳率: 20.5%
浏览 762
已采纳

Chance to Encounter a Girl

Long long ago, there was a small but beautiful country, in which lived a very smart girl. The girl was very interested in travelling, every day she travelled from one town to another. Her sense of direction is so bad that she always forgot the road which she had came from and randomly chose a town in the country to move on. She never went out of the country.

You, a very cool man, go back to the past using a time machine and travelled through the country. If you could meet the girl, love would happen and the story would have a happy end.

So, what's the probability of a happy end?

The country consists of n * n blocks (n = 2*k - 1; k = 2,...,50), each block is a town. Every day, the girl can move up, left, down or right to a neighbor town, and you, the cool man, must move right until you meet the girl or get outside the country.

Assume the left bottom town is (0, 0). Initially, the girl is in the town (n/2, n/2) and you are in (-1, n/2).

The following figure is a sample of country (3 * 3), G is the girl's inital position and Y is yours.

    +-+-+-+
    | | | |
  +-+-+-+-+
  |Y| |G| |
  +-+-+-+-+
    | | | |
    +-+-+-+

Input

There are multiple test cases(less than 30). For each case there is only one line containing an integer n (n = 2 * k - 1; 1 < k <= 50). Proceed until the end of file.

Output

For each test case you should print the possibility of a happy end. Round to four decimal digits.

Sample Input

3

Sample Output

0.6667

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-03-07 15:05
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改