Topic Link:
Http://uva.onlinejudge.org/index.php? option=com_onlinejudge&itemid=8&category=460&page=show_problem&problem=4144
First save the code, go to sleep.
Code:
#include <iostream> #include <cstdio> #include <algorithm> #include <cctype> using names
Pace std;
const int LCM = 2520;
const int MAXN = 100010;
int W, h, N, idx;
inline bool GetTime (int x, int y, int& A, int& b) {int tx1, TX2, ty1, ty2;
if (a) {tx1 = (w-x) *lcm/a, tx2 = (x) *lcm/a;
if (tx1<0 && tx2<0) return false;
else{if (x>=w | | | x<=0) return FALSE;
TX1 = 0, tx2 = 1e9;
} if (b) {ty1 = (h-y) *lcm/b, ty2 = (-y) *lcm/b;
if (ty1<0 && ty2<0) return false;
else{if (y>=h | | | y<=0) return FALSE;
ty1 = 0, ty2 = 1e9;
if (tx1 > Tx2) Swap (TX1, TX2);
if (ty1 > Ty2) Swap (ty1, ty2);
if (tx1<0) tx1=0;
if (ty1<0) ty1=0;
A = Max (tx1, ty1);
b = min (tx2, ty2);
Return a<b;
} struct node{int pos; InT type;
BOOL operator< (const NODE&RHS) const{if (POS!= rhs.pos) return pos<rhs.pos;
Return type<rhs.type;
}}arr[maxn*2];
int main () {int ncase;
scanf ("%d", &ncase);
while (ncase--) {int x,y,a,b;
scanf ("%d%d%d", &w,&h,&n);
IDX = 0;
for (int i=0; i<n; ++i) {scanf ("%d%d%d%d", &x,&y,&a,&b);
if (GetTime (x, Y, A, B)) {arr[idx].pos = A;
Arr[idx++].type = 1;
Arr[idx].pos = b;
Arr[idx++].type =-1;
} sort (arr, arr+idx);
int cur=0, maxx=0;
for (int i=0; i<idx; ++i) {if (arr[i].type>0) Maxx = Max (++cur, Maxx);
else--cur;
printf ("%d\n", Maxx);
return 0; }
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/