问题 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. 【android】 中文URL资源找不到的问题

    在博客园安卓客户端时,遇到过中文资源找不到的问题 背景:在使用PICASSO的时候,遇到过中文路径加载失败.比如 https://images0.cnblogs.com/news_topic/携程.j ...

  2. MySql中concat函数的用法(链接字符串)

    MySQL中concat函数使用方法:CONCAT(str1,str2,…) 返回结果为连接参数产生的字符串.如有任何一个参数为NULL ,则返回值为 NULL. 注意:如果所有参数均为非二进制字符串 ...

  3. HttpWebRequest 返回BadRequest(400) 同时返回Response

    今天用Fiddler分析安卓APP的一个登陆功能的时候,账号和密码错误会返回相应的消息,并且状态码是400. 正常用法: /// <summary> /// 读取返回的内容 /// < ...

  4. JS变量比较陷阱

    我们觉得JS简单是因为它是弱类型的语言,不像java那样对对类型那样敏感,但js也有其不尽人意的地方. 在java中我们无法将数字与字符串直接比较,而js能,而且能直接转换成数值比较,但是如果是字符串 ...

  5. LeetCode (226):Invert Binary Tree 递归实现

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1 Trivia:This problem was ...

  6. Python3.6 安装、后续终端pip 安装模块命令

    1. 下载安装包 https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe 2. 安装python3.6 增加环境变量(打钩.红框很 ...

  7. Jquery9 事件对象

    学习要点: 1.事件对象 2.冒泡和默认行为 JavaScript 在事件处理函数中默认传递了 event 对象,也就是事件对象.但由于浏览器的兼容性,开发者总是会做兼容方面的处理.jQuery 在封 ...

  8. Kafka架构

    一.Kafka介绍 Kafka是Linkin在2010年开源的分布式发布订阅消息系统,Kafka是高吞吐量的消息订阅系统. 二.Kafka结构 Kafka由三部分构成,producer.broker. ...

  9. (转)C#自制Web 服务器开发:用C#开发自己的Web服务器

    当输入:127.0.0.1:5050 GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, */* Accept-Language: zh- ...

  10. GCC嵌入式汇编(内嵌汇编)入门

    GCC嵌入式汇编(内嵌汇编)入门 1. 入门 在C中嵌入汇编的最大问题是如何将C语言变量与指令操作数相关联.当然,gcc都帮我们想好了.下面是是一个简单例子. asm("fsinx %1, ...