题意:

应该不难读懂。

做法:

我们可以把雨滴看做静止不动,然后maze(这题的那个人)就是往左上方运动就可以了,计算出maze能跑到的最远的点,然后就是求起点和终点所构成的线段与每个雨滴交的时间,注意题目说每个雨滴可能会相交,所以我们对于每个雨滴算出相交的区间,然后对这些区间进行合并并且计算答案。

注意点:

1.maze有可能一开始就在雨滴里面。

2.还有maze穿了一部分的雨滴就被追上了。 (竟然没有这种数据)

3.两线段共线的情况,就是三角形右边的那条边 与 maze的线段共线, 这种情况之下也要细分,但我没判这种情况也AC了,说明没有这种数据,但考虑问题时我们需要把它考虑进去。 (竟然没有这种数据)

知道以上注意点AC应该不远了,毕竟不是什么难题,我的代码没有写第三种情况。

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define pii pair <double, double>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
const double eps = 1e-8;
int dcmp(double x) {
if (fabs(x) < eps)
return 0;
return x > eps ? 1 : -1;
}
struct point {
double x, y;
point() { }
point(double x, double y) :
x(x), y(y) {
}
double operator *(const point &t) const {
return x * t.x + y * t.y;
}
point operator -(const point &t) const {
return point(x - t.x, y - t.y);
}
point operator +(const point &t) const {
return point(x + t.x, y + t.y);
}
point operator *(const double &t) const { // 注意是 点乘
return point(t * x, t * y);
}
} s, e; double v1, v2, v, t, x, T;
double ans;
int n;
inline double F(double x) {
return x * x;
}
double cross(const point &o, const point &a, const point &b) {
return (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x);
}
double dis(const point &a, const point &b) {
return sqrt(F(a.x - b.x) + F(a.y - b.y));
} bool segSegIntersect(const point &a, const point &b, const point &l, const point &r) { //两线段相交(不考虑共线)
return cross(a, b, l) * cross(a, b, r) < eps
&& cross(l, r, a) * cross(l, r, b) < eps;
} double intersect(const point &a, const point &b, const point &l, const point &r) { // 两直线求交点的x
double ret = a.x;
double t = ((a.x - l.x) * (l.y - r.y) - (a.y - l.y) * (l.x - r.x))
/ ((a.x - b.x) * (l.y - r.y) - (a.y - b.y) * (l.x - r.x));
return ret + (b.x - a.x) * t;
} vector<double> vec; //记录与雨滴的交点
vector<pii> res; //记录被雨滴打到的每个时间段 struct rain {
point o, a, b, c;
double r, h;
/* 雨滴三角形的三个点标号
* c
* /_\
* a b
*/
void in() {
scanf("%lf%lf%lf%lf", &o.x, &o.y, &r, &h);
a = o, b = o, c = o;
a.x -= r;
b.x += r;
c.y += h;
}
bool inside(const point &p) { //点是否在雨滴里面(包括边界)
return (dis(o, p) - eps < r && p.y - eps < o.y)
|| (cross(c, a, p) > -eps && cross(c, b, p) < eps
&& p.y > o.y + eps);
} void intersectC() { //与雨滴的半圆 交 求交点
point b = s, d = e - s;
double A = d * d;
double B = (b - o) * d * 2;
double C = (b - o) * (b - o) - r * r;
double dlt = B * B - 4 * A * C;
if (dlt < -eps) return; if (dlt < eps) dlt = 0; //消除dlt负数零的情况
else dlt = sqrt(dlt); double t = (-B - dlt) / (2 * A);
point tp = b + d * t;
if (tp.x - eps < s.x && tp.x + eps > e.x && tp.y - eps < o.y) //因为是半圆,注意把没用的点判掉
vec.pb(tp.x); t = (-B + dlt) / (2 * A);
tp = b + d * t;
if (tp.x - eps < s.x && tp.x + eps > e.x && tp.y - eps < o.y)
vec.pb(tp.x); } void intersectT() { //与雨滴的三角形 交 求交点 (水平的线段不算在其中)
double x;
if (segSegIntersect(a, c, s, e)) {
x = intersect(a, c, s, e);
if (x - eps > e.x && x + eps < s.x)
vec.pb(x);
}
if (segSegIntersect(c, b, s, e)) {
x = intersect(c, b, s, e);
if (x - eps > e.x && x + eps < s.x)
vec.pb(x);
}
} void gao() { vec.clear();
intersectC();
intersectT();
if (inside(s)) vec.pb(s.x);
if (inside(e)) vec.pb(e.x);
sort(vec.begin(), vec.end());
int cnt = unique(vec.begin(), vec.end()) - vec.begin();
if (cnt >= 2) //取最大和最小的两个交点 就是被雨滴打到的时间段 的 两端点
res.pb(mp(vec[0], vec[cnt - 1]));
}
} p; int main() {
int i, j, cas;
scanf("%d", &cas);
for (int ca = 1; ca <= cas; ca++) {
scanf("%lf%lf%lf%lf%lf%d", &v1, &v2, &v, &t, &x, &n);
T = v1 * t / (v2 - v1) + t;
s.x = x;
s.y = 0;
e.x = x - v1 * T;
e.y = v * T;
ans = 0;
res.clear();
for (i = 0; i < n; i++) {
p.in();
p.gao();
} //对每个时间段去重后计算答案
sort(res.begin(), res.end()); double r = e.x;
int SZ = res.size();
for (i = 0; i < SZ; i++) {
if (res[i].X - eps < r && r - eps < res[i].Y) {
ans += res[i].Y - r;
r = res[i].Y;
}
else if (r - eps < res[i].X) {
ans += res[i].Y - res[i].X;
r = res[i].Y;
} }
printf("Case %d: %.4f\n", ca, ans / v1);
}
return 0;
}

HDU 4637 Rain on your Fat brother 线段与半圆和线段交 简单题的更多相关文章

  1. HDU 3340 Rain in ACStar(线段树+几何)

    HDU 3340 Rain in ACStar pid=3340" target="_blank" style="">题目链接 题意:给定几个多 ...

  2. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. FJNU 1154 Fat Brother And His Love(胖哥与女神)

    FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS   Memory Limit: 257792K [Description] [ ...

  4. FJNU 1153 Fat Brother And XOR(胖哥与异或)

    FJNU 1153 Fat Brother And XOR(胖哥与异或) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目描述] ...

  5. FJNU 1155 Fat Brother’s prediction(胖哥的预言)

    FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  6. FJNU 1152 Fat Brother And Integer(胖哥与整数)

    FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题 ...

  7. FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)

    FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS   Memory Limit: 257792K [Description] [题目 ...

  8. FJNU 1151 Fat Brother And Geometry(胖哥与几何)

    FJNU 1151 Fat Brother And Geometry(胖哥与几何) Time Limit: 1000MS   Memory Limit: 257792K [Description] [ ...

  9. FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)

    FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术) Time Limit: 1000MS   Memory Limit: 257792K [Description ...

随机推荐

  1. java-No exception of type ConfigurationException can be thrown; an exception type must be a subclass of Throwable

    功能:读配置文件 java菜鸟:导入工程在报名处就开始报错,第一次遇到 import org.apache.commons.lang3.StringUtils; import org.apache.c ...

  2. Func<T, TResult> 委托的由来和调用和好处(为了高大上,为了白富美)

    Func<T, TResult>是系统的内置委托的中最常用的一个.特点就是必须有一个返回值.(func委托有多个重载,所有重载的最后一个参数就是返回值的类型,前面的是参数类型).注:没有返 ...

  3. android view生命周期

    onFinishInflate() 当View中所有的子控件均被映射成xml后触发 onMeasure( int ,  int ) 确定所有子元素的大小 onLayout( boolean ,  in ...

  4. hdu 1115(计算多边形重心)

    题意:已知一多边形没有边相交,质量分布均匀.顺序给出多边形的顶点坐标,求其重心. 分析: 求多边形重心的题目大致有这么几种: 1,质量集中在顶点上.n个顶点坐标为(xi,yi),质量为mi,则重心 X ...

  5. [Everyday Mathematics]20150224

    设 $A,B$ 是 $n$ 阶实对称矩阵, 它们的特征值 $>1$. 试证: $AB$ 的特征值的绝对值 $>1$.

  6. inno setup详细使用教程

    前段时间我完成了几个软件的汉化,想把它们打包起来,可是苦于我是一个很菜的鸟,很笨的瓜,只好上网找关于安装程序制作的文章.不幸我没能找到:-( 没法只好自己去华军软件园里找找制作安装程序的软件,并一把下 ...

  7. Android百度地图开发(五)公交线路详情搜索、多条线路显示

    一.公交线路详情检索 获取公交线路的详情主要分来两步,1.获取公交线路的Uid,2.通过Uid获取公交线路详情. 1.获取公交线路的Uid: /* * 获得公交线路图的Uid,并且根据系Uid发起公交 ...

  8. Python开发者最常犯的10个错误

    Python是一门简单易学的编程语言,语法简洁而清晰,并且拥有丰富和强大的类库.与其它大多数程序设计语言使用大括号不一样 ,它使用缩进来定义语句块. 在平时的工作中,Python开发者很容易犯一些小错 ...

  9. Git 提交后开始自动构建

    设定Git仓库的钩子 一般路径为 xxx.git/hooks 参考文档 https://git-scm.com/docs/githooks 修改 post-receive #!/bin/bash wh ...

  10. 【数据结构与算法分析——C语言描述】第一章总结 引论

    这一章主要复习了一些数学知识,像指数.对数.模运算.级数公式:还有2种证明方法,归纳假设法和反证法.所幸以前学过,重新拾捡起来也比较轻松. 简要地复习了递归,提出了编写递归例程的四条基本法则: 基准情 ...