873
技术社区[云栖]
uva 1398 - Meteor 模拟 99
最近多练练简单题,简单的扫描线
/*
author:jxy
lang:C/C++
university:China,Xidian University
**If you need to reprint,please indicate the source**
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int w,h,n;
const int inf=1e9;
struct point
{
point(){};
point(int x,int y):time(x),type(y){};
int time;
int type; //1为开始,-1为结束
bool operator <(const point &a) const
{
return time<a.time||(a.time==time&&type<a.type);
}
};
point org[200005];
int update(int w,int b,int a,int &L,int &R)
{
if(a==0)
{
if(b<=0||b>=w)R=L-1;
}
else if(a>0)
{
L=max(L,-2520*b/a);
R=min(R,2520*(w-b)/a);
}
else
{
L=max(L,2520*(w-b)/a);
R=min(R,-2520*b/a);
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int cnt=0;
scanf("%d%d%d",&w,&h,&n);
int x,y,vx,vy;
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&x,&y,&vx,&vy);
int l=0,r=inf;
update(w,x,vx,l,r);
update(h,y,vy,l,r);
if(l<r)
{
org[cnt++]=point(l,1);
org[cnt++]=point(r,-1);
}
}
sort(org,org+cnt);
int ans=0,t=0;
for(int i=0;i<cnt;i++)
{
t+=org[i].type;
ans=max(ans,t);
}
printf("%d\n",ans);
}
}
最后更新:2017-04-03 15:22:11
上一篇:
网络子系统22_队列规则传输接口
下一篇:
COM编程入门第一部分——什么是COM,如何使用COM
买单宝平台程序系统开发
Java Date Time 教程-java.util.Date
measureChildren的工作原理
【演讲实录+视频】走近40+世界级AI专家!第三届中国人工智能大会资料分享
SVN commit:remains in tree-conflict错误的解决办法
景安专项网安扶持项目启动 为河南企业保驾护航
poj 1828 Monkeys' Pride 模拟
PostgreSQL 使用pg_xlogdump找到误操作事务号
Master-Slave Synchronization for MySQL
足球数据 | 被对手进球后的十分钟内最有可能扳回比分