uva1398 - Meteor
来源:互联网 发布:淘宝扒皮精灵家 编辑:程序博客网 时间:2024/06/06 10:55
题意:
n个流星,二维,给定初始坐标和速度,及一个坐标(0,0)到(w,h)的矩形。有个望远镜要拍摄,问能够同时在望远镜中拍摄到的最大的流星数目为多少?
思路:
要想所有流星在矩形里同时出现的数目最多,那么确定流星在矩形里出现的时段最重要,如果求得每科流星在矩形里出现的时间区间,那么让其时间区间排序后扫描一下,保留最大流星个数即可。
求时间区间时可将速度分为x,y方向的两个量分量分开求,进入时间的话要x,y两个分量都进入矩形才算,出来时间恰恰相反。
代码:
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>using namespace std;struct Event{double t;int type;bool operator <(const Event & e)const{return t<e.t || (t == e.t && type > e.type);}} even[100005 * 2];void update(int x, int a, int w, double &l, double & r){if (a == 0){if (x <= 0 || x >= w) r = l - 1;// no ans}else if (a>0)//正方向{l = max(l, -(double)x / a);r = min(r, (double)(w - x) / a);}else{l = max(l, (double)(w - x) / a);r = min(r, -(double)x / a);}}int main(){int cas; scanf("%d", &cas);while (cas--){int w, h, n, num = 0, x, y, a, b;scanf("%d %d %d", &w, &h, &n);for (int i = 0; i<n; ++i){scanf("%d %d %d %d", &x, &y, &a, &b);double L = 0, R = 1e9;update(x, a, w, L, R);update(y, b, h, L, R);if (R>L){even[num++] = (Event){ L, 0 };even[num++] = (Event){ R, 1 };}}sort(even, even + num);int ans = 0, cnt = 0;for (int i = 0; i<num; ++i){if (even[i].type == 0) ans = max(ans, ++cnt);else cnt--;}printf("%d\n", ans);}return 0;}
0 0
- uva1398 - Meteor
- Uva1398 Meteor
- uva1398 - Meteor
- uva1398 Meteor
- Uva1398--Meteor(扫描线)
- 【转换模型+扫描线】【UVA1398】Meteor
- uva1398
- meteor
- meteor
- Meteor
- uva1398 线性扫描
- 例题1.20 流星 UVa1398
- meteor.js
- 3905 - Meteor
- Meteor Shower
- 初识Meteor
- meteor安装
- Meteor Start
- 网页滚动到底部自动加载数据
- sql 已知两点的经纬度,求距离
- 2015年工作报告与总结
- Python自动化查询CNKI并获取查询结果
- 手机相册的基本使用
- uva1398 - Meteor
- 理解Hadoop分布式文件系统HDFS(二)
- 【总结】深插浅出重拾Linux
- 为已有的web project项目加入maven支持,并使用myeclipse的插件.
- sp<> wp<>-Android中定义了两种智能指针强指针sp和弱指针wp
- RUST语法
- hdu3342 Legal or Not(简单拓扑排序判定)
- 圆形ImageView系列(一)-----Xfermode+View
- LightOJ--1149--Factors and Multiples(二分图好题)