zoj 3664
来源:互联网 发布:linux man help 编辑:程序博客网 时间:2024/05/22 00:31
//暴力lca:这个题,从头找,最后一个符合条件的点就是最近祖先点//每次画一条线,一个矩形变成2个,这不就是二叉树嘛?#include <stdio.h>#include <iostream>#include <string.h>using namespace std;const int N=3000;struct pot{ int x,y; pot(int a,int b) { x=a,y=b; }};struct re{ int x,y,x2,y2; void read(int xl,int yl,int xr,int yr) { x=xl,y=yl,x2=xr,y2=yr; } bool in(int xl,int yl,int xr,int yr) { return xl>=x && yl>=y && xr<=x2 && yr<=y2; }};re c[N];int xl,yl,xr,yr;int num;//矩形的编号int lson[N],rson[N],cnt[N];//cnt表示编号为i的矩阵内含线的条数int n,q;void update_from_root(int u){ cnt[u]++; if(lson[u]==-1) { lson[u]=++num,rson[u]=++num; c[lson[u]].read(xl,yl,c[u].x2,c[u].y2); c[rson[u]].read(c[u].x,c[u].y,xr,yr); } else { if(c[lson[u]].in(xl,yl,xr,yr)) update_from_root(lson[u]); else update_from_root(rson[u]); }}int query(int u){ if(lson[u]==-1) return cnt[u]; if(c[lson[u]].in(xl,yl,xr,yr)) return query(lson[u]); if(c[rson[u]].in(xl,yl,xr,yr)) return query(rson[u]); return cnt[u];}int main(){ while(~scanf("%d%d%d%d",&xl,&yl,&xr,&yr)) { memset(cnt,0,sizeof cnt); memset(lson,-1,sizeof lson); memset(rson,-1,sizeof rson); c[1].read(xl,yl,xr,yr); scanf("%d%d",&n,&q); int n1=n; num=1; while(n--) { scanf("%d%d%d%d",&xl,&yl,&xr,&yr); if(xl>xr) {int tmp=xl;xl=xr;xr=tmp;} if(yl>yr){int tmp=yl;yl=yr;yr=tmp;} update_from_root(1); } while(q--) { scanf("%d%d%d%d",&xl,&yl,&xr,&yr); if(xl>xr) {int tmp=xl;xl=xr;xr=tmp;} if(yl>yr){int tmp=yl;yl=yr;yr=tmp;} printf("%d\n",n1+1-query(1)); } } return 0;}/*-10 -10 10 105 1-10 0 10 05 -10 5 0-5 0 -5 10-5 5 10 55 -5 10 -50 -3 7 -3*/
阅读全文
0 0
- zoj 3664
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- ZOJ
- pytorch入门(二)——自动求导函数
- Field discoveryClient in com.demo.eureka_client.controller.DcController required a bean of type 'com
- oracle-编码
- Eclipse-设置格式化代码时不格式化注释
- Spring boot之hello world故障
- zoj 3664
- c++ make_heap, pop_heap, push_heap, sort_heap详解
- 数据结构实验之图论七:驴友计划
- 酒店管理系统数据库设计说明书
- 换钱的最少货币数
- LeetCode-03 穷举
- Python入门(03) -- 字典
- Thinkphp中使用PHPExcel 导入导出excel
- Spark性能优化:资源调优篇