uva1398 线性扫描
2014-12-23 22:54
211 查看
/* *********************************************** Author :fisty Created Time :2014/12/23 21:56:54 File Name :uva1398.cpp ************************************************ */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; #define MAX_N 100000+100 void update(int x, int a, int w, double& L, double& R){ //0 < x + at < w if(a == 0){ if(x <= 0 || x >= w) R = L - 1; //无解 }else if(a > 0){ // -x/a < t < (w-x)/a L = max(L, -(double)x/(double)a); R = min(R, (double)(w-x)/(double)a); }else{ //a < 0 L = max(L, (double)(w-x)/(double)a); R = min(R, -(double)x/(double)a); } } struct node{ double x; int type; //node(double _x = 0, int _type = 0):x(_x), type(_type){} bool operator < (const node& a) const { return x < a.x || (x == a.x && type > a.type); } }event[MAX_N*2]; int main() { //freopen("in.txt","r",stdin); //freopen("out.txt","w",stdout); cin.tie(0); std::ios::sync_with_stdio(false); int t; cin >> t; while(t--){ int n,w, h; int e = 0; cin >> w >> h; cin >> n; //printf("w:%d h:%d n:%d\n", w, h, n); for(int i = 0;i < n; i++){ int x, y, a, b; cin >> x >> y >> a >> b; //printf("%d %d %d %d\n", x,y,a,b); double L = 0, R = 1e9; update(x , a, w , L, R); update(y , b, h , L, R); //printf("L:%d R:%d\n",L,R); if(R > L){ event[e++] = (node){L, 0}; event[e++] = (node){R, 1}; } } sort(event, event + e); int cnt = 0, ans = 0; for(int i = 0;i < e; i++){ if(event[i].type == 0){ ans = max(ans, ++cnt); }else{ cnt--; } } cout << ans << endl; } return 0; }
相关文章推荐
- Seoul 2007 / UVa 1398 Meteor (排序&线性扫描)
- 【转换模型+扫描线】【UVA1398】Meteor
- 【转换模型+扫描线】【UVA1398】Meteor
- UVA 1398 - Meteor(排序+扫描方法+几何)
- UVA 1432 - Fire-Control System(技巧枚举+线性扫描)
- Uva1398--Meteor(扫描线)
- UVa 1398 Meteor 解题报告(扫描线)
- UVA 1398 Meteor(扫描线)
- UVa 1442 (线性扫描) Cave
- UVA 1398 - Meteor
- 线性扫描+种子填充算法 实现区域填充
- UVA11991线性查询
- UVALive 2519 Radar Installation 雷达扫描 区间选点问题
- UVALive - 4851 Restaurant 扫描
- UVA 11258 String Partition(线性DP)
- UVA - 242 线性DP
- Uva1606 Amphiphilic Carbon Molecules【例题8-6】【极角扫描法】【不懂!】
- uva 1442 Cav(左右各扫描一次)
- UVaLive 3695 Distant Galaxy (扫描线)
- UVA 348 最优矩阵链乘(线性动态规划)