UVALive LA3905 Meteor (扫描线统计)
来源:互联网 发布:非农数据最新消息 编辑:程序博客网 时间:2024/06/06 08:44
http://acm.hust.edu.cn/vjudge/contest/131137#problem/A
题解:
需要一些等价思想,在矩形内就等价于在两条线段上,就比如你横坐标的位置变化在(0,W),而你纵坐标的变化在(0,H)内,(注意是两个开区间)如果两个同时存在,那么就证明在照相机矩形内。
题目中给的速度,已经是X,Y两个方向的,所以我们只需要计算每个流星进入矩形的时间tin和出矩形的时间tout,其中我们为了避免流星永远不会经过矩形,我们只需要赋好初值就行了。
然后我们直接统计就行了。
注意排序过程中,先出的流星要先统计。
(虽然这道题是大白书的,但是很多人的代码和大白书的代码一模一样是为什么?虽然我写的代码很差,但是至少是我自己写的把。)
我是按照位置分类讨论的,按照大白书上的其实按照速度来讨论,确实更容易。原谅我太愚蠢!
#include<bits/stdc++.h>using namespace std;#define pb push_backconst double Dmax=1e18;const double eps=1e-7;vector<pair<double,int> >V;int xi,yi,ai,bi,W,H;double ty1,ty2,tx1,tx2;void f() { if(xi>0&&xi<W) { tx1=0.0; if(ai>0) { tx2=abs(xi-W)*1.00/(ai); } else if(ai<0) { tx2=fabs(xi*1.00/(ai)); } else { tx2=Dmax; } } else { if(xi<0) { if(ai<=0)tx1=Dmax,tx2=-Dmax; else { tx1=fabs(xi*1.00/(ai)); tx2=fabs((xi-W)*1.00/(ai)); } } else if(xi>W) { if(ai>=0)tx1=Dmax,tx2=-Dmax; else { tx1=fabs((W-xi)*1.00/(ai)); tx2=fabs(xi*1.00/(ai)); } } else if(!xi) { tx1=0.00; if(ai<=0)tx2=-Dmax; else tx2=fabs(W*1.00/(ai)); } else { tx1=0.00; if(ai>=0)tx2=-Dmax; else tx2=fabs(W*1.00/(ai)); } } if(yi>0&&yi<H) { ty1=0.0; if(bi>0) { ty2=fabs((yi-H)*1.00/(bi)); } else if(bi<0) { ty2=fabs(yi*1.00/(bi)); } else { ty2=Dmax; } } else { if(yi<0) { if(bi<=0)ty1=Dmax,ty2=-Dmax; else { ty1=fabs(yi*1.00/(bi)); ty2=fabs((yi-H)*1.00/(bi)); } } else if(yi>H) { if(bi>=0)ty1=Dmax,ty2=-Dmax; else { ty1=fabs((H-yi)*1.00/(bi)); ty2=fabs(yi*1.00/(bi)); } } else if(!yi) { ty1=0.00; if(bi<=0)ty2=-Dmax; else ty2=fabs(H*1.00/(bi)); } else { ty1=0.00; if(bi>=0)ty2=-Dmax; else ty2=fabs(H*1.00/(bi)); } }}int dcmp(double val1,double val2) { if(fabs(val1-val2)<=eps)return 0; return (val1-val2)>0?1:-1;}bool mycmp(pair<double,int> _1,pair<double,int> _2){ if(dcmp(_1.first,_2.first)){ return _1.first<_2.first; } return _1.second<_2.second;}int main() {#ifdef tangge freopen("LA3905.in","r",stdin);#endif // tangge int T,n; scanf("%d",&T); while(T--) { scanf("%d%d%d",&W,&H,&n); V.clear(); for(int i=0; i<n; ++i) { scanf("%d%d%d%d",&xi,&yi,&ai,&bi); f(); double tin=max(tx1,ty1),tout=min(tx2,ty2); if(tin>=tout || !dcmp(tin,Dmax) || !dcmp(tout,-Dmax)) {} else { V.pb(make_pair(tin,1)),V.pb(make_pair(tout,-1)); } } sort(V.begin(),V.end(),mycmp); int len=(int)V.size(); int ans=0,now=0; for(int i=0; i<len; ++i) { now+=V[i].second; ans=max(ans,now); } printf("%d\n",ans); } return 0;}
1 0
- UVALive LA3905 Meteor (扫描线统计)
- LA3905-Meteor(扫描线)
- UVALive 3905-Meteor-扫描线算法
- UVALive - 3905 Meteor 统计
- la3905 Meteor 流星 事件触发
- Uva1398--Meteor(扫描线)
- UVA 1398 Meteor(扫描线)
- LA 3905 Meteor 扫描线 -
- LA 3905 Meteor [扫描线]
- LA3905
- LA3905
- LA3905
- 【转换模型+扫描线】【UVA1398】Meteor
- UVALive - 3905 [Meteor]
- UVa 1398 Meteor 解题报告(扫描线)
- UVALive 7261 Xiongnu's Land 扫描线
- uvalive 6864 扫描线和技巧
- 【扫描线】uvalive 7261 Xiongnu's Land
- Codeforces 233C Partial Sums(特殊三角矩阵压缩)
- java.io.IOException: Attempted read from closed stream.
- 欢迎使用CSDN-markdown编辑器
- 在SurfaceView中实现覆盖刷新和脏矩形刷的方法
- leetcode Binary Tree Maximum Path Sum
- UVALive LA3905 Meteor (扫描线统计)
- 进程间通信-信号量
- 安卓探究纵深博客
- GeokoFx (1)替换 webbrowser ,环境搭建
- iOS开发实现TouchID指纹解锁
- SDWebImage加载图片设置cookie
- HDU2866 Special Prime
- QCustomPlot之绘图的基础
- listview支持多种item显示处理