uva11722 Joining with Friend
来源:互联网 发布:windows虚拟机软件 编辑:程序博客网 时间:2024/05/19 02:20
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 xed. In fact your train can reach in
any time within the interval [ t 1 ;t 2 ] with equal probability. The
other one will reach in any time within the interval [ s 1 ;s 2] 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 rst line of input will denote
the number of cases T ( T< 500). Each of the following T line will
contain 5 integers t 1 , t 2 , s 1 , s 2 , w (360 t 1 < t 2 < 1080,
360 s 1 < s 2 < 1080 and 1 w 90). All inputs t 1 , t 2 , s 1 , s
2 and w are given in minutes and t 1 , t 2 , s 1 , s 2 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 1 e
把两辆火车到达时间分别看成
具体实现上,分类讨论的情况比较多,可以分别计算两条直线以下的矩形面积再相减。
#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;int t1,t2,s1,s2,w;double calc(int x){ if (t1+x>=s2) return (s2-s1)*(t2-t1); if (t2+x<=s1) return 0; if (t1+x>=s1&&t2+x>=s2) return (t2-t1)*(s2-s1)-(double)(s2-t1-x)*(s2-t1-x)/2; if (t1+x<=s1&&t2+x<=s2) return (double)(t2-s1+x)*(t2-s1+x)/2; if (t1+x<=s1&&t2+x>=s2) return (double)(2*t2-s1-s2+2*x)*(s2-s1)/2; return (double)(t1+t2-2*s1+2*x)*(t2-t1)/2;}int main(){ int T,K; scanf("%d",&T); for (K=1;K<=T;K++) { scanf("%d%d%d%d%d",&t1,&t2,&s1,&s2,&w); printf("Case #%d: %.8f\n",K,(calc(w)-calc(-w))/(t2-t1)/(s2-s1)); }}
- Uva11722 Joining with Friend
- uva11722 Joining with Friend
- Uva11722 joining with friend 概率 几何计算
- UVA 11722 Joining with Friend
- UVA 11722 Joining with Friend
- UVA 11722 - Joining with Friend(概率)
- uva 11722 - Joining with Friend(概率)
- UVA - 11722 Joining with Friend (概率)
- UVA 11722 Joining with Friend【概率】
- UVA 11722 Joining with Friend 图形面积+概率
- UVa 11722 - Joining with Friend (概率 数形结合)
- UVA 11722 Joining with Friend 概率与期望
- uva11722(概率)
- UVA11722Joining with Friend概率dp
- Joining an array of keys to a hash with key value pairs like excel vlookup
- Joining data
- UVA11722(见面概率)
- friend
- scrollview设置view的可见性导致布局错误
- oracle创建用户
- MySQL——InnoDB锁问题(六)
- Spark Yarn-cluster 与 Yarn-client
- PHP Ajax 跨域问题
- uva11722 Joining with Friend
- 基于dialog的可移动的自定义键盘
- 分词IKAnalyze
- intent详解(二)
- k-近邻算法(Python实现)
- 使用JAVA向微软消息队列(MSMQ)发送和接收消息
- 使用nginx+tomcat负载均衡
- Java 编程题自动评分技术的研究与实现(一)
- 分库分表中间件