问题 I: Kid and Ants

时间限制: 1 Sec  内存限制: 128 MB
提交: 42  解决: 33
[提交][状态][讨论版]

题目描述

Kid likes interest question,although he don’t like ants so much.

Assume there is a infinite long stick whose direction is from East to West. In addition, there are n

ants on the stick and their original orientation is arbitrary(East or West).Then from a moment,all

the ants will climb on the stick at the same speed toward their original orientation.Once two ants

touch each other, they will change their orientation and go up climbing.(May be some ants will

never meet other ants).So now Kid’s task is to calculate the mathematical expectation of the meets

between ants.

输入

There are multiple cases.

For each case,there is a integer n.(1<=n<=10^9)

输出

For each case,just print the mathematical expectation(retain three decimals)

样例输入

2
10

样例输出

0.250
11.250

提示

When n=2,there 4 cases(E indicates the orientation of the ant is East and W is West)

(left is East and right is West)

{E,E},{E,W},{W,E},{W,W}

And the number of meets is 0,0,1,0, so the mathematical expectation is (0+0+1+0)/4=0.250.

随便取两只蚂蚁,方案数n*(n-1)/2,对这两只蚂蚁有四种状态,一种碰撞
 
#include <cstdio>
using namespace std;
int main(){
int n;
while(scanf("%lf",&n)==1&&n){
printf("%.3f\n",(double)n*(n-1)/8.0);
}
return 0;
}

  

 

NEU 1497 Kid and Ants 思路 难度:0的更多相关文章

  1. POJ 1083 Moving Tables 思路 难度:0

    http://poj.org/problem?id=1083 这道题题意是有若干段线段,每次要求线段不重叠地取,问最少取多少次. 因为这些线段都是必须取的,所以需要让空隙最小 思路: 循环直到线段全部 ...

  2. NEU 1496 Planar map 计算几何,点到线段距离 难度:0

    问题 H: Planar map 时间限制: 1 Sec  内存限制: 128 MB提交: 24  解决: 22[提交][状态][讨论版] 题目描述 Tigher has work for a lon ...

  3. NEU 1495 a interesting game 大数 难度:1

    问题 G: a interesting game 时间限制: 1 Sec  内存限制: 128 MB提交: 29  解决: 10[提交][状态][讨论版] 题目描述 One day,Kid is in ...

  4. UVa 10382 - Watering Grass 贪心,水题,爆int 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  5. UVa 10970 - Big Chocolate 水题 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  6. Uva LA 3902 - Network 树形DP 难度: 0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  7. Uva 12124 Uva Live 3971 - Assemble 二分, 判断器, g++不用map.size() 难度:0

    题目 https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_pr ...

  8. UVa 11384 - Help is needed for Dexter 分析, 树状数组 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

  9. UVa 11210 - Chinese Mahjong 模拟, 枚举 难度: 0

    题目 https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&a ...

随机推荐

  1. 189. Rotate Array(两次反转)

    DescriptionHintsSubmissionsDiscussSolution   Pick One Rotate an array of n elements to the right by  ...

  2. JSON 转 对象

    Json对象与Json字符串的转化.JSON字符串与Java对象的转换   一.Json对象与Json字符串的转化 1.jQuery插件支持的转换方式: $.parseJSON( jsonstr ); ...

  3. c++之旅:操作符重载

    操作符重载 操作符重载可以为操作符添加更多的含义,操作符重载的作用的对象是类 那些操作符可以重载 除了下面几个操作符不能重载外,其它的操作符都能重载 . :: .* ?: sizeof 操作符重载的本 ...

  4. 超级强大的vim配置(vimplus)--续集

    An automatic configuration program for vim 安装(github地址:https://github.com/chxuan/vimplus.git, 欢迎star ...

  5. 解决Linux 下server和client 通过TCP通讯:accept成功接收却报错的问题

    今天在写简单的TCP通讯例子的时候,遇到了一个问题:server 和client能够连接成功,并且client也能够正常发送,但server就是接收不到,在网上搜索一番后,终于解决了问题.在这里整理如 ...

  6. left4dead2 常用配置

    难度控制 z_difficulty [Easy, Normal, Hard, Impossible]

  7. shell内置命令eval的具有什么作用

    答:把变量中的内容当成命令来执行

  8. maven(一)maven自带的插件

    关于org.apache.maven.plugins 前言 maven提供了很多插件给我们使用,解释3个java环境常用的maven插件, maven-jar-plugin, maven-compli ...

  9. flume 1.7 安装与使用

    Flume安装 系统要求: 需安装JDK 1.7及以上版本 1. 下载二进制包 下载页面:http://flume.apache.org/download.html 1.7.0下载地址:http:// ...

  10. 高并发下,php与redis实现的抢购、秒杀功能

    抢购.秒杀是如今很常见的一个应用场景,主要需要解决的问题有两个: 1 高并发对数据库产生的压力 2 竞争状态下如何解决库存的正确减少("超卖"问题) 对于第一个问题,已经很容易想到 ...