https://vjudge.net/problem/UVALive-3905

计算出每个点在相框中的时间段,扫描线做即可

关键在如何快速计算每个点在相框中的时间段。对每个点进行运动分解,进入的时间L是x进入和y进入的最大,退出时间R是x退出和y退出的最小,画图看一下即可

画图同时可以发现不经过相框的时候会导致L >= R

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <vector>
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? (-1 * (a)) : (a))
inline void swap(int &a, int &b)
{
int tmp = a;a = b;b = tmp;
}
inline void read(int &x)
{
x = ;char ch = getchar(), c = ch;
while(ch < '' || ch > '') c = ch, ch = getchar();
while(ch <= '' && ch >= '') x = x * + ch - '', ch = getchar();
if(c == '-') x = -x;
} const int INF = 0x3f3f3f3f;
const int MAXN = + ; int tt,w,h,n,x[MAXN],y[MAXN],a[MAXN],b[MAXN],flag[MAXN << ], cnt[MAXN << ], tot, t[MAXN << ], ans, tag; bool cmp(int a, int b)
{
return t[a] == t[b] ? flag[a] > flag[b] : t[a] < t[b];
} inline void update(int x, int a, int w, int &L, int &R)
{
if(a == )
{
if(x <= || x >= w) R = L - ;
}
else if(a > )
{
L = max(L, -x * / a);
R = min(R, (w - x) * / a);
}
else
{
L = max(L, (w - x) * / a);
R = min(R, -x * / a);
}
} int main()
{
read(tt);
for(;tt;--tt)
{
read(w), read(h), read(n);
for(register int i = ;i <= n;++ i) read(x[i]), read(y[i]), read(a[i]), read(b[i]);
tot = ;
for(register int i = ;i <= n;++ i)
{
int L = , R = INF;
update(x[i], a[i], w, L, R);
update(y[i], b[i], h, L, R);
if(L < R)
{
t[++tot] = L;flag[tot] = ;cnt[tot] = tot;
t[++tot] = R;flag[tot] = ;cnt[tot] = tot;
}
}
std::sort(cnt + , cnt + + tot, cmp);
ans = tag = ;
for(register int i = ;i <= tot;++ i)
{
if(flag[cnt[i]]) -- tag;
else ++ tag;
ans = max(ans, tag);
}
printf("%d\n", ans);
}
return ;
}

LA3905

最新文章

  1. Bzoj3041 水叮当的舞步
  2. js计算字符串出现个数
  3. 在Linux(Ubuntu)下搭建ASP.NET Core环境并运行 继续跨平台
  4. [原创]VM虚拟机安装centos6.4详细图文教程
  5. liunx下tomcat启动报错
  6. Android 使用MediaStore.Images和 Cursor查询本地图片和图片缩略图
  7. Scrapy的shell命令(转)
  8. SQLite for xamarin
  9. premake Ubuntu下的安装
  10. C++实现动态顺序表
  11. links
  12. 【quickhybrid】JSBridge的实现
  13. 框架页面高度自动刷新Javascript脚本
  14. 使用Ninject的一般步骤
  15. npm那些事儿
  16. [转]vnpy乱乱谈 02架构
  17. 【转】vector中erase()的使用注意事项
  18. JavaScript之this,call,apply
  19. tomcat8 tomcat-users相关配置
  20. mysql 数据库备份的多种方式

热门文章

  1. Linux真好玩阿,不过我家电脑不行,运行不够流畅
  2. Foundation框架系列-NSArray
  3. mybatis 查询sql时foreach使用法
  4. leetcode-第五场双周赛-1133-最大唯一数
  5. 关于str的打印格式
  6. Linux中要重启apache服务与在windows是有很大的区别,下面我们来介绍一下
  7. 【自家测试】2017-12-16 FJOI2016 d1
  8. 服务器重启,自动重启httpd
  9. WebLogic使用总结(二)——WebLogic卸载[转]
  10. Spark-内存管理调优