uva 1398 - Meteor
来源:互联网 发布:上海私人调查公司 知乎 编辑:程序博客网 时间:2024/05/17 04:00
点击打开链接uva 1398
思路:扫描法
分析:
1 不难发现,流星的轨迹是没有用的,有意义的只是每个流星在照相机视野内出现的时间段
2 那么我们就可以通过去求出没个流星在矩形内的时间段,然后利用扫描法去求。
具体见刘汝佳<<训练指南46页>>
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;const int MAXN = 100010;struct Event{ double x; int type; bool operator<(const Event& rhs)const{ return x < rhs.x || x == rhs.x && type == 1; }};Event events[MAXN*2];//求时间段void update(int x , int a , int w , double&left , double& right){ if(a == 0){ if(x <= 0 || x >= w) right = left-1; } else if(a > 0){ left = max(left , -x*1.0/a); right = min(right , (w-x)*1.0/a); } else{ left = max(left , (w-x)*1.0/a); right = min(right , -x*1.0/a); }}int main(){ int Case; scanf("%d" , &Case); while(Case--){ int w , h , n , pos = 0; scanf("%d%d%d" , &w , &h , &n); for(int i = 0 ; i < n ; i++){ int x , y , a , b; scanf("%d%d%d%d" , &x , &y , &a , &b); double left = 0 , right = 1e9; update(x , a , w , left , right);//水平风向求时间段 update(y , b , h , left , right);//竖直方向求时间段 if(right > left){ events[pos++] = (Event){left , 0};//左端点事件 events[pos++] = (Event){right , 1};//右端点事件 } } int ans = 0; int cnt = 0; for(int i = 0 ; i < pos ; i++){ if(events[i].type == 0) //碰到左端点更新cnt和ans ans = max(ans , ++cnt); else cnt--; } printf("%d\n" , ans); } return 0;}
- uva 1398 - Meteor
- uva 1398 - Meteor
- UVA 1398 - Meteor
- UVA 1398 - Meteor
- UVA之1398 - Meteor
- UVA 1398 Meteor
- Uva---1398Meteor
- UVA - 1398 Meteor
- uva 1398 - Meteor 模拟 99
- uva 1398 - Meteor(贪心)
- UVA 1398 Meteor(扫描线)
- Uva-Live 3905-Meteor
- Seoul 2007 / UVa 1398 Meteor (排序&线性扫描)
- UVA 1398 - Meteor(排序+扫描方法+几何)
- UVa 1398 Meteor 解题报告(扫描线)
- meteor
- meteor
- Meteor
- HTTP Keep-Alive详解
- js_array_splice
- 23种设计模式的形象比喻
- Mysql中Innodb与Mysiam区别
- CF 292E Copying Data
- uva 1398 - Meteor
- Android 自定义网络移动网络接入点
- 数据库sql中的convert用法
- 第四次上机报告
- 搭建Android开发环境(方式二):在Eclipse中安装ADT插件
- Ajax里的onreadystatechange的作用是什么
- CIRCOS教程翻译 3.1——Wedge Highlights
- ubuntu中安装SystemC
- 用代码创建各种快捷方式