NC15532 Happy Running
题目
题目描述
Happy Running, an application for runners, is very popular in CHD.
In order to lose weight, fdf decides to run k meters per day with Happy Running. Let’s regard the school as a circular runway with total length of x meters, and fdf could start running clockwise at a random point on the runway. Then Happy Running will randomly show two punching-card points (打卡点). Because of the poor physical strength, fdf decides to finish running only by completing the punch, whether or not complete the goal of k meters.
One day, before running, fdf wants to know whether he can achieve the goal today, and he asks you to help him to calculate the probability of completing the goal running k meters.
Note that, fdf should punch card one by one which means that he will punch card at the first point before the second, even if he reaches the second point first.
It is guaranteed that punching-card points and the point fdf starts running will appears randomly with equal probability and the three points won’t be coincide.
输入描述
The first line contains an integer number T, the number of test cases.
ith of each next T lines contains two integer numbers k,x(1 ≤ k,x ≤ 10^9).
输出描述
For each test case print the probability of completing the goal, round to two decimal places.
示例1
输入
3
2 2
4 3
2 1
输出
0.50
0.22
0.00
题解
知识点:概率论。
考虑固定起点,因为起点在哪都一样,只需要考虑 \(a,b\) 的相对位置。接下来,利用几何概型分类讨论:
- 当 \(k\leq x\) 时,概率为 \(1- \dfrac{k^2}{2x^2}\) 。
- 当 \(x < k \leq 2x\) 时,概率为 \(\dfrac{(2x-k)^2}{2x^2}\) 。
- 当 \(2x < k\) 时,概率为 \(0\) 。
时间复杂度 \(O(1)\)
空间复杂度 \(O(1)\)
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool solve() {
int k, x;
cin >> k >> x;
if (k <= x) cout << fixed << setprecision(2) << 1 - (long double)k * k / 2 / x / x << '\n';
else if (k <= 2 * x) cout << fixed << setprecision(2) << (long double)(2 * x - k) * (2 * x - k) / 2 / x / x << '\n';
else cout << fixed << setprecision(2) << 0 << '\n';
return true;
}
int main() {
std::ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
if (!solve()) cout << -1 << '\n';
}
return 0;
}
NC15532 Happy Running的更多相关文章
- Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)
作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...
- Running Dubbo On Spring Boot
Dubbo(http://dubbo.io/) 是阿里的开源的一款分布式服务框架.而Spring Boot则是Spring社区这两年致力于打造的简化Java配置的微服务框架. 利用他们各自优势,配置到 ...
- Android PopupWindow Dialog 关于 is your activity running 崩溃详解
Android PopupWindow Dialog 关于 is your activity running 崩溃详解 [TOC] 起因 对于 PopupWindow Dialog 需要 Activi ...
- IntelliJ运行下载的Servlet时报错 Error running Tomcat 8.5.8: Unable to open debugger port (127.0.0.1:49551): java.net.SocketException
学习Java Servlet时,从Wrox上下载了示例代码,准备run/debug时发现以下错误: Error running Tomcat 8.5.8: Unable to open debugge ...
- teamviewer "TeamViewer Daemon is not running
执行下面的命令问题解决: # teamviewer --daemon enable enable Sat Jan :: CST Action: Installing daemon () for 'up ...
- mysql 有报错 ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
sh-4.1# /etc/init.d/mysqld status ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql ...
- Errors occurred during the build. Errors running builder 'JavaScript Validator' on project
1.问题:Errors occurred during the build. Errors running builder 'JavaScript Validator' on project 2.解决 ...
- The network bridge on device VMnet0 is not running
The network bridge on device VMnet0 is not running. The virtual machine will not be able to communic ...
- ERROR! MySQL is running but PID file could not be found
/etc/init.d/mysql status提示ERROR! MySQL is running but PID file could not be found先打印MYSQL进程ps aux | ...
- 问题解决:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...
随机推荐
- Linux系统下安装JDK8和Maven3.8.5
一.下载JDK8Linux版本 官网下载太慢了,小编这里为大家下载好了: 链接:百度网盘地址 提取码:ov24 二.下载Maven maven3.8.5下载链接 三.使用xftp上传到linux上 四 ...
- 【C/C++】 代码质量控制手段
问题引入 多人协作开发的项目,没有统一的代码规范,那么最终的编写状态必定风格迥异,产生的结果:对内,阅读审核代码是很痛苦的:对外,公司形象就是差. 单干的项目也必须要严格按照代码规范,因为最终还是会对 ...
- 【TouchGFX】visua studio 自定义路径宏
很好奇 touchgfx 的 visual studio 工程文件中路径符号 $(TouchGFXReleasePath)是哪里定义的,经查这就是一个宏替换 自定义宏方式
- javase项目 正常导入jar 包
1,在 java project 目录下新建 lib 文件夹 2,将 mysql 的 jar 包 复制到 新建的 lib 文件夹 3,选中 lib 下的 jar 包 , 右键点击选择 build pa ...
- 基本操作Linux
基本操作Linux 关机,重启# 关机 shutdown -h now # 重启 shutdown -r now 查看系统,CPU信息# 查看系统内核信息 uname -a # 查看系统内核版本 ca ...
- TiDB的搭建与维护过程
TiDB的搭建与维护过程 背景 总结一下TiDB的搭建以及简单维护过程. 目标: 简单快速的创建TiDB数据库,以及进行备份恢复等工作. TiDB 简介 TiDB(全称:Ti Distributed ...
- [转帖]SSL数字证书分类DV/OV/EV
SSL证书的分类主要是通过下面两个维度进行分类: 1.根据验证模式分类 根据CA机构对申请者的身份审核范围分为:DV证书.OV证书.EV证书. 1.1.DV证书(域名证书) DV(Domain Val ...
- [转帖]windos的kafka设置账号密码
1.kafka配置文件 server.properties增加 listeners=SASL_PLAINTEXT://127.0.0.1:9092 advertised.listeners=SASL_ ...
- 使用linux上面powershell安装vm powercli 连接vcenter 通过计划任务自动创建部分虚拟机的快照以及自动清理过期快照的办法
经过一晚上的折腾, 终于验证出来一个非常简单的方法. 也比较好理解和使用. 这里简单记录一下: 使用linux上面powershell安装vm powercli 连接vcenter 通过计划任务自动创 ...
- MYsql备份恢复简单过程
1. 备份数据库 建完数据库更新完补丁之后进行数据库的备份操作. mysqldump -uroot --databases yourdatabase -p > /home/yourdatabas ...