1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <algorithm> 5 #include <vector> 6 using namespace std; 7 struct me{ 8 me(){;} 9 me(double time, int type){this->t=time; this->type=type;} 10 me(const me& a){this->t = a.t; this->type=a.type;} 11 double t; 12 int type; //0=end, 1=start 13 }; 14 bool mysort(const me& a, const me& b){ 15 if(a.t-b.t<1e-9 and b.t-a.t<1e-9)return (a.type < b.type); 16 else return (a.t < b.t); 17 } 18 int main(){ 19 int T; 20 int w, h, n; 21 int x, y, a, b; 22 int pt, ans, tmp; 23 double sx, sy, ex, ey; 24 vector<me> time(200002); 25 scanf("%d", &T); 26 while(T--){ 27 scanf("%d%d%d", &w, &h, &n); 28 pt=ans=tmp=0; 29 for(int i=0 ; i<n ; ++i){ 30 scanf("%d%d%d%d", &x, &y, &a, &b); 31 if(a==0){ sx=(x>0 and x<w)?0:2147483647; ex=(x>0 and x<w)?2147483647:0;} 32 else{ sx=(0.-x)/(double)a; ex=(double)(w-x)/(double)a; 33 if(sx>ex){ swap(sx, ex);} 34 } 35 36 if(b==0){ sy=(y>0 and y<h)?0:2147483647; ey=(y>0 and y<h)?2147483647:0;} 37 else{ sy=(0.-y)/(double)b; ey=(double)(h-y)/(double)b; 38 if(sy>ey){ swap(sy, ey);} 39 } 40 41 if(sx<0) sx=0; if(sy<0) sy=0; 42 if(ex<0) ex=0; if(ey<0) ey=0; 43 sx=max(sx, sy); ex=min(ex, ey); 44 if(ex-sx<1e-9){continue;} 45 time[pt++]=me(sx, 1); time[pt++]=me(ex, 0); 46 } 47 sort(time.begin(), time.begin()+pt, mysort); 48 for(int i=0 ; i<pt ; ++i){ 49 if(time[i].type==0){ 50 --tmp; 51 }else{ 52 ++tmp; 53 } 54 if(tmp>ans) ans=tmp; 55 } 56 printf("%d\n", ans); 57 } 58 return 0; 59 }
2014年7月25日 星期五
UVA-1398, Meteor
判斷速度分量是否為零後的else忘記加大括弧讓我2WA= =
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言
TEST