题意:

应该不难读懂。

做法:

我们可以把雨滴看做静止不动,然后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. Linux获取时间日期方法

    linux中用shell获取昨天.明天或多天前的日期:在Linux中对man date -d 参数说的比较模糊,以下举例进一步说明:# -d, --date=STRING display time d ...

  2. CURL: CURLE_COULDNT_CONNECT问题探究

    摘自::  存储系统研究: socket connect error 99(Cannot assign request address) 这是最近使用libcurl写http服务的压力测试的时候遇到的 ...

  3. HDU 2151 Worm

    Worm Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  4. hibernate建表一对多 一的一方控制多的方

    级联操作,操作class对象的时候 级联操作 student Classes.java文件 package cn.itcast.hiberate.sh.domain; import java.util ...

  5. Quartz.net 2.0的使用说明

    Quartz.NET是一个开源的作业调度框架,是OpenSymphony 的 Quartz API的.NET移植,它用C#写成,可用于WinForm和ASP.NET应用中.它提供了巨大的灵活性而不牺牲 ...

  6. 使用python三方库xlrd解析excel数据

    excel是平常用的比较多的一种数据格式,而在自动化测试过程中,解析其数据以供脚本使用就是一个重要的工作,幸好已有现存的三方库供使用,而不必重新造轮子. 一.安装xlrd模块 到python官网下载h ...

  7. CString类Format()的用法 .xml

    pre{ line-height:1; color:#9f1d66; background-color:#f0f0f0; font-size:16px;}.sysFunc{color:#5d57ff; ...

  8. backbone-1.3.3源码解析-----------Event

    第一次写,写的不对的请指正 backbone.js中的Event实现了自定义事件.自定义事件就是一个对象的键值对,key为事件名,value为一个function数组.在backbone这个对象中有一 ...

  9. 如何解决grails2.3.2中不能运行fork模式

    升级到grails 2.3.2之后,运行时报如下的异常: Exception in thread "main" Error | Forked Grails VM exited wi ...

  10. Srum框架

    Srum包括三个角色.四个会议.及三个产出物,如下图所示: