题意:

应该不难读懂。

做法:

我们可以把雨滴看做静止不动,然后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. Android 适配多种ROM的快捷方式

    快捷方式 应该来说 很多人都做过,我们就来看一下基本的快捷方式 是怎么实现的,会有什么问题? 首先 肯定要获取权限: <!-- 添加快捷方式 --> <uses-permission ...

  2. 【转】使用ngrok快速地将本地Web服务映射到外网

    为什么要使用ngrok? 作为一个Web开发者,我们有时候会需要临时地将一个本地的Web网站部署到外网,以供它人体验评价或协助调试等等,通常我们会这么做: 找到一台运行于外网的Web服务器 服务器上有 ...

  3. RequireJS进阶(二) 转

    这一篇来认识下打包工具的paths参数,在入门一中就介绍了require.config方法的paths参数.用来配置jquery模块的文件名(jQuery作为AMD模块时id为“jquery”,但文件 ...

  4. C++调试 输出数组内容和数组名

    #include <cstdio> using namespace std; //函数定义 #define printArr(arr,n,format) \ printf("%s ...

  5. [转] VS 整合NUnit进行单元测试

    Jeff Wong原文 5分钟实现VS2010整合NUnit进行单元测试 1.下载安装NUnit(最新win版本为NUnit-2.6.0.12051.msi) http://www.nunit.org ...

  6. MSSQL 查询分组前N条记录

    sql语句中,查询分组中前n条记录的sql语句如下 第一种方法 select * from consultingfeebill awhere n>(select count(*) from co ...

  7. hihocoder 1356 分隔相同整数 简单贪心

    分析:考虑贪心,考虑填ans[i],前i-1个合法,现在剩下一些数, 那么挑出出现次数最多的数,次数为mx,当前剩余总数为sum 如果sum-mx>=mx-1那么肯定有解,这个想想就知道了(这种 ...

  8. Linux环境Weblogic10g服务部署

    1.先安装XManager: 2.进入XShell,远程连接Linux主机后,按如下操作即可打开XManager配置WebLogic部署服务: [root@server36 bin]# cd /[ro ...

  9. DuiLib消息处理剖析

    本来想自己写写duilib的消息机制来帮助duilib的新手朋友,不过今天发现已经有人写过了,而且写得很不错,把duilib的主干消息机制都说明了,我就直接转载过来了,原地址:http://blog. ...

  10. 写在阿里去IOE一周年

    [文/ 任英杰] 去年5月17日,阿里巴巴支付宝最后一台IBM小型机在下线,标志着阿里完成去IOE.随后一场去IOE运动不断发酵,甚至传闻IBM中国去年损失了20%的合同额. 去了IOE,奔向何方?阿 ...