hdu 2461 Rectangles
求矩形的并 矩形个数 1...20
m次询问 回答要求的r个矩形的并
容斥原理
dfs优化: 遇到面积交为0时 这个dfs分支可以不下去了 #include <iostream>
#include <string>
#include<sstream>
#include <cmath>
#include <map>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
//#define LL long long
#define LL __int64
struct Rectan
{
int x1,y1;
int x2,y2;
Rectan jiao(Rectan &R)
{
Rectan t;
t.x1=max(x1,R.x1);
t.y1=max(y1,R.y1);
t.x2=min(x2,R.x2);
t.y2=min(y2,R.y2);
return t;
}
int area()
{
if(x1>=x2||y1>=y2) return ;
return (x2-x1)*(y2-y1);
}
}ar[];
int rc[],r;
int ans;
void dfs(int deep,Rectan R,int index)
{
Rectan t;
int i;
for(i=index;i<=r;i++)
{
t=R.jiao(ar[rc[i]]);
if(t.area())
{
if(deep&) ans-=t.area();
else ans+=t.area();
dfs(deep+,t,i+);
}
}
}
int main()
{
int n,m;
int i,Case=,q;
while(scanf("%d %d",&n,&m),n|m)
{
for(i=;i<=n;i++)
scanf("%d %d %d %d",&ar[i].x1,&ar[i].y1,&ar[i].x2,&ar[i].y2);
printf("Case %d:\n",Case++);
for(q=;q<=m;q++)
{
ans=;
scanf("%d",&r);
for(i=;i<=r;i++)
scanf("%d",&rc[i]);
for(i=;i<=r;i++)
{
ans+=ar[rc[i]].area();
dfs(,ar[rc[i]],i+);
}
printf("Query %d: %d\n",q,ans);
}
printf("\n"); }
return ;
}
hdu 2461 Rectangles的更多相关文章
- HDU 2461 Rectangles#容斥原理
http://acm.hdu.edu.cn/showproblem.php?pid=2461 题目很简单,但是由于询问数M可以很大,所以容易超时,这道题学到了在结构体里面写函数的方法,这样子效率更高, ...
- hdu 2461(AC) & poj 3695(TLE)(离散化+矩形并)
Rectangles Time Limit: 5000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2056 Rectangles
Rectangles Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 2461 线段树扫描线
给出N个矩形,M次询问 每次询问给出R个.问这R个矩形围成的面积 经典扫面线求面积并,对每次询问的R个点离散化一下 #include "stdio.h" #include &quo ...
- HDU 1892 See you~ (二维树状数组)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1892 See you~ Problem Description Now I am leaving h ...
- HDU 1264 Counting Squares(线段树求面积的并)
Counting Squares Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1828 Picture(线段树扫描线求周长)
Picture Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- HDU 1506 Largest Rectangle in a Histogram (dp左右处理边界的矩形问题)
E - Largest Rectangle in a Histogram Time Limit:1000MS Memory Limit:32768KB 64bit IO Format: ...
- HDU 1542 Atlantis(线段树扫描线+离散化求面积的并)
Atlantis Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
随机推荐
- 关于http请求ContentType:application/x-www-form-urlencoded
在又一次http请求过程中,模拟post请求提交form表单数据一直提示部分参数为空,后面检查发现是缺少ContentType:application/x-www-form-urlencoded的原因 ...
- [Vue]实例化Vue时的两种挂载方式el与$mount
Vue 的$mount()为手动挂载,在项目中可用于延时挂载(例如在挂载之前要进行一些其他操作.判断等),之后要手动挂载上.new Vue时,el和$mount并没有本质上的不同. 1.el Vue实 ...
- javascript中的定时器
本文地址:[http://www.xiabingbao.com/javascript/2015/04/20/javascript-timer/] 在以前的文章[javascript中的定时器]中,简单 ...
- java实现赋值excel模板,并在新文件中写入数据,并且下载
/** * 生成excel并下载 */ public void exportExcel(){ File newFile = createNewFile(); //File newFile = new ...
- Docker 进入容器的几种方式
进入Docker容器比较常见的几种做法如下: 使用docker attach 使用SSH 使用nsenter 使用exec 一.使用docker attach进入Docker容器 Docker提供了a ...
- Rem实现移动端适配
移动端适配 web页面跑在手机端(h5页面) 跨平台 基于webview() 基于webkit 常见适配方法 pc端采用display:inline-block,让div盒子横着排 移动web:采用定 ...
- 转:Hive SQL的编译过程
Hive是基于Hadoop的一个数据仓库系统,在各大公司都有广泛的应用.美团数据仓库也是基于Hive搭建,每天执行近万次的Hive ETL计算流程,负责每天数百GB的数据存储和分析.Hive的稳定性和 ...
- 小练习:vaild number
1.描述 给定字符串,若该字符串表示的是数字,则输出true,否则输出false 2.分析 题目一看感觉不难,做起来却很麻烦,首先是数字的各种表示要知道,然后就是对这些不同形式的数字进行筛选判断.该题 ...
- linux FTP 操作
1.登陆: ftp 172.xxx.xxx.xxx 按提示输入用户名和密码 2.上传: 单个文件:put /路径/文件名 批量: 输入 prom 此命令是关闭交互(否则总是询问你是否要上传) 输入下载 ...
- hdu1814
题解: 2-sat nm暴力 虽然似乎复杂度最低 代码: #include<cstdio> #include<cmath> #include<algorithm> ...