问题 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. MyBatisPartA

    (正在补充) 1.从第一个程序开始,通过mybatis实现数据库表内容的增删改查 (源码zip包) 1.0准备工作 建数据库mybatis,在其中创建表sql语句如下: ; -- ---------- ...

  2. 64. Minimum Path Sum(最小走棋盘 动态规划)

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  3. Java ArrayList详细介绍和使用示例

    ①对ArrayList的整体认识 ArrayList是一个数组队列,相当于动态数组.与Java中的数组相比,它的容量能动态增长.它继承了AbstractList,实现了List,RandomAcces ...

  4. 由浅入深之Tensorflow(2)----logic_regression实现

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

  5. centos7防火墙的简单配置介绍

    centos7版本 1.查看已开放的端口(默认不开放任何端口) firewall-cmd --list-ports 2.开启80端口 firewall-cmd --zone=public(作用域) - ...

  6. .NET Core + EF 报nuget包不兼容

    错误信息如下: 严重性 代码 说明 项目 文件 行 禁止显示状态错误 NU1107 Microsoft.EntityFrameworkCore 中检测到版本冲突.直接安装/引用 Microsoft.E ...

  7. Android-服务中监听电源键和Home键的广播、在锁屏下仍然工作的方法

    Android-服务中监听电源键和Home键的广播  http://blog.csdn.net/u014657752/article/details/49512485 Android开发之如何监听让服 ...

  8. Printf的缓冲机制

    转:https://blog.csdn.net/qq_25424545/article/details/78772959 今天用fork()写程序时候,突然发现自己对Printf的缓冲机制还是有些不够 ...

  9. rowspan && colspan

    > 跨行 <html> <body> <table width="> <tr> <th>col1</th> &l ...

  10. SpringMvc接受特殊符号参数被转义

    WEB开发时,在前端通过get / post 方法传递参数的时候  如果实参附带特殊符号,后端接收到的值中特殊符号就会被转义 例如该请求: http://localhost:10001/demo/in ...