Joining with Friend

You are going from Dhaka to Chittagong by train and you came to know one of your old friends is going from city Chittagong to Sylhet. You also know that both the trains will have a stoppage at junction Akhaura at almost same time. You wanted to see your friend there. But the system of the country is not that good. The times of reaching to Akhaura for both trains are not fixed. In fact your train can reach in any time within the interval [t1, t2] with equal probability. The other one will reach in any time within the interval [s1, s2] with equal probability. Each of the trains will stop for w minutes after reaching the junction. You can only see your friend, if in some time both of the trains is present in the station. Find the probability that you can see your friend. Input The first line of input will denote the number of cases T (T < 500). Each of the following T line will contain 5 integers t1, t2, s1, s2, w (360 ≤ t1 < t2 < 1080, 360 ≤ s1 < s2 < 1080 and 1 ≤ w ≤ 90). All inputs t1, t2, s1, s2 and w are given in minutes and t1, t2, s1, s2 are minutes since midnight 00:00. Output For each test case print one line of output in the format ‘Case #k: p’ Here k is the case number and p is the probability of seeing your friend. Up to 1e − 6 error in your output will be acceptable. Sample Input 2 1000 1040 1000 1040 20 720 750 730 760 16 Sample Output Case #1: 0.75000000 Case #2: 0.67111111

比较显然的线性规划,几何概型,之前一道类似的题出到了我们数学卷子上,被我秒了。。。

主要是求面积,分好情况

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#include <cmath>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(int &a, int &b)
{
long long tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const int INF = 0x3f3f3f3f; int t1,t2,s1,s2,t,ca,w; double calc(int w)
{
if(t1 + w >= s2) return (s2 - s1) * (t2 - t1);
if(t2 + w <= s1) return ;
if(t1 + w >= s1)//left
{
if(s2 - w >= t2) return (double)(t1 + w - s1 + t2 + w - s1) * (t2 - t1) * 0.5; //right
else return (s2 - s1) * (t2 - t1) - (double)(s2 - t1 - w) * (s2 - w - t1) * 0.5; //up
}
else
{
if(s2 - w >= t2) return (double)(t2 + w - s1) * (t2 - s1 + w) * 0.5; //right
else return (double)(t2 - s2 + w + t2 - s1 + w) * (s2 - s1) * 0.5;//up
}
return ;
} int main()
{
read(t);
for(;t;--t)
{
++ ca;
read(t1), read(t2), read(s1), read(s2), read(w);
printf("Case #%d: %.8lf\n", ca, (calc(w) - calc(-w)) / ((s2 - s1) * (t2 - t1)));
}
return ;
}

UVA11722

最新文章

  1. FILE文件流的中fopen、fread、fseek、fclose的使用
  2. CSS3 border-image 属性
  3. 新安装loadrunner无法录制脚本的原因之一及解决方案
  4. mysql错误一例:ERROR 1030 (HY000): Got error 28 from storage engine
  5. BZOJ2051——A Problem For Fun
  6. poj 3841 Double Queue (AVL树入门)
  7. [转]处理程序“PageHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”
  8. java异常处理机制Exception
  9. addListener添加事件监听器,第三个参数useCapture (Boolean) 的作用
  10. Swift—重写-备
  11. Inno Setup for Windows service
  12. CSS检测的高像素密度屏幕设备
  13. WuKong
  14. ActiveMQ消息的发送原理
  15. Zephyr学习(三)启动过程
  16. test TSS Work about
  17. Day 5 字典的操作
  18. P3164 [CQOI2014]和谐矩阵
  19. html向js传递id
  20. Oracle工作笔记

热门文章

  1. springboot启动器:spring-boot-starter
  2. 次短路 /// dijkstra oj1597
  3. VMware Workstation 10 配置Ubuntu环境
  4. 激活office2016的心路历程
  5. pycharm IDE在导入自定义模块时提示有错,但实际没错
  6. StringUtils工具
  7. Qt---坐标系统
  8. html--浮动高度塌陷问题
  9. 2016.8.19上午初中部NOIP普及组比赛总结
  10. Django项目:CMDB(服务器硬件资产自动采集系统)--11--07CMDB文件模式测试采集硬件数据