标签:style http color os io for ar 时间
题目连接:uva 11722 - Joining with Friend
题目大意:你和朋友乘火车,并且都会路过A市,给定两人可能到达A市的时段,火车会停w,问说两人可以见面的概率。
解题思路:y = x + w 和y = x - w在给定时间内围成的面积除以时间的总面积,就是求面积的时候要分情况处理。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int t1, t2, s1, s2, w;
double sum;
double solve (int k) {
double ret = 0;
if (s2 > t2 + k && s1 > t1 + k) {
double r = max(t2 + k - s1, 0);
ret = sum - r * r / 2;
} else if (s2 > t2 + k) {
double r = 2 * s2 - t1 - t2 - 2 * k;
ret = r * (t2 - t1) / 2;
} else if (s1 > t1 + k) {
double r = s2 + s1 - 2 * k - 2 * t1;
ret = r * (s2 - s1) / 2;
} else {
double r = max(s2 - k - t1, 0);
ret = r * r / 2;
}
if (k < 0)
ret = sum - ret;
return ret;
}
int main () {
int cas;
scanf("%d", &cas);
for (int kcas = 1; kcas <= cas; kcas++) {
scanf("%d%d%d%d%d", &t1, &t2, &s1, &s2, &w);
sum = 1.0 * (t2 - t1) * (s2 - s1);
double ans = solve(w) + solve(-w);
printf("Case #%d: %.8lf\n", kcas, 1 - ans / sum);
}
return 0;
}
uva 11722 - Joining with Friend(概率),布布扣,bubuko.com
uva 11722 - Joining with Friend(概率)
标签:style http color os io for ar 时间
原文地址:http://blog.csdn.net/keshuai19940722/article/details/38478165