HDU 4637 Rain on your Fat brother 线段与半圆和线段交 简单题
题意:
应该不难读懂。
做法:
我们可以把雨滴看做静止不动,然后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 线段与半圆和线段交 简单题的更多相关文章
- HDU 3340 Rain in ACStar(线段树+几何)
HDU 3340 Rain in ACStar pid=3340" target="_blank" style="">题目链接 题意:给定几个多 ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- FJNU 1154 Fat Brother And His Love(胖哥与女神)
FJNU 1154 Fat Brother And His Love(胖哥与女神) Time Limit: 2000MS Memory Limit: 257792K [Description] [ ...
- FJNU 1153 Fat Brother And XOR(胖哥与异或)
FJNU 1153 Fat Brother And XOR(胖哥与异或) Time Limit: 1000MS Memory Limit: 257792K [Description] [题目描述] ...
- FJNU 1155 Fat Brother’s prediction(胖哥的预言)
FJNU 1155 Fat Brother’s prediction(胖哥的预言) Time Limit: 1000MS Memory Limit: 257792K [Description] [ ...
- FJNU 1152 Fat Brother And Integer(胖哥与整数)
FJNU 1152 Fat Brother And Integer(胖哥与整数) Time Limit: 1000MS Memory Limit: 257792K [Description] [题 ...
- FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼)
FJNU 1156 Fat Brother’s Gorehowl(胖哥的血吼) Time Limit: 1000MS Memory Limit: 257792K [Description] [题目 ...
- FJNU 1151 Fat Brother And Geometry(胖哥与几何)
FJNU 1151 Fat Brother And Geometry(胖哥与几何) Time Limit: 1000MS Memory Limit: 257792K [Description] [ ...
- FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术)
FJNU 1157 Fat Brother’s ruozhi magic(胖哥的弱智术) Time Limit: 1000MS Memory Limit: 257792K [Description ...
随机推荐
- git常用知识整理
分布式和集中版本控制的区别 分布式版本控制系统与集中式版本控制系统有何不同呢?首先,分布式版本控制系统根本没有“中央服务器”,每个人的电脑上都是一个完整的版本库,这样,你工作的时候,就不需要联网了,因 ...
- 虚拟机VMware tools作用以及其安装
虚拟机VMware tools的作用(1). 更新虚拟机中的显卡驱动, 使虚拟机中的XWindows可以运行在SVGA模式下.在客户操作系统中安装Mware Tools非常重要.如果不安装VMware ...
- jdbc操作数据库返回结果集的注意事项
import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sq ...
- head 命令
head 与 tail 就像它的名字一样的浅显易懂,它是用来显示开头或结尾某个数量的文字区块,head 用来显示档案的开头至标准输出中,而 tail 想当然尔就是看档案的结尾. 1.命令格式: hea ...
- 任务(Tasks)
在Eclipse中用TODO标签管理任务,利用这个功能可以方便地将项目中一些需要处理的任务记录下来.我们可以通过在java注释里添加任务标签来标记一个任务,任务可以通过Tasks(任务)视图来察看. ...
- Epic - Spiral Matrix
Given aNXN matrix, starting from the upper right corner of the matrix start printingvalues in a coun ...
- (转)MFC消息机制
转自:http://blog.csdn.net/kongfuxionghao/article/details/35882533
- 定制一个FlatBuffers编译器
个人并不喜欢FlatBuffers编译器生成的代码,原因是我已经习惯了unix风格的代码. 不喜欢之处大致有以下: 1 命名法使用了Pascal命名法,而我个人习惯了小写字母加下划线式的unix式命名 ...
- 开源框架DNN简介以及安装
donetnuke 是一款免费的开源cms框架,目前也有收费版,不过免费版也可以适应大家大部分的需求.我前些阵子是老板让我在20天内,做好一个官网并且发布,并且指定使用dnn这个框架,考虑到又可以学习 ...
- Apache Spark shell的实例操作
1.scala> val inFile = sc.textFile("./spam.data") 作用是将spam.data当作文本文件加载到Spark中,将spam.dat ...