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 ...
随机推荐
- (转)SQL Server中的索引结构与疑惑
说实话我从没有在实际项目中使用过索引,仅知道索引是一个相当重要的技术点,因此我也看了不少文章知道了索引的区别.分类.优缺点以及如何使用索引.但关于索引它最本质的是什么笔者一直没明白,本文是笔者带着这些 ...
- spring mvc:输出json,输出多个json
spring mvc:输出xml/输出json 用到的注解@ResponseBody @ResponseBody用来输出json/xml等格式数据(非html) controller输出用到的类 or ...
- JSP 表达式语言
JSP 表达式语言 JSP表达式语言(EL)使得访问存储在JavaBean中的数据变得非常简单.JSP EL既可以用来创建算术表达式也可以用来创建逻辑表达式.在JSP EL表达式内可以使用整型数,浮点 ...
- 11.深入理解读写锁ReentrantReadWriteLock
protected final int tryAcquireShared(int unused) { /* * Walkthrough: * 1. If write lock held by anot ...
- write 系统调用耗时长的原因
前一阵子公司一部门有人叫帮忙调查,说他们write系统调用基本上是个位数微秒就返回,或者说几十us,但偶尔出现几次write系统调用达到几百毫秒和情况.大家都知道,通过vfs进行write,都是写写到 ...
- nyi63——树
#include<bits/stdc++.h> using namespace std; int cnt; struct node { int data; int flag; node * ...
- Linux下记录所有用户的登录和操作日志
Linux下记录所有用户的登录和操作日志 一般我们可以用history命令来查看用户的操作记录,但是这个命令不能记录是哪个用户登录操作的,也不能记录详细的操作时间,且不完整:所以误操作而造成重要的 ...
- 尝试优化骨骼动画计算的意外收获——使用嵌入式汇编对float转int进行优化
本文为大便一箩筐的原创内容,转载请注明出处,谢谢:http://www.cnblogs.com/dbylk/p/4984530.html 公司引擎目前是使用CPU计算骨骼动画(采用了D3DX提供的函数 ...
- centos静默安装oracle12c
配置系统和安装所需软件包 关闭selinux 临时关闭(不用重启) [root@SVR-3-125 ~]# setenforce 0 修改配置文件(需要重启): 将SELINUX=enforcing ...
- poj3068
题解: 最小费用最大流 每一次找最短的 代码: #include<cstdio> #include<cmath> #include<cstring> #includ ...