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 ...
随机推荐
- winform中的ListBox和ComboBox绑定数据
将集合数据绑定到ListBox和ComboBox控件,界面上显示某个属性的内容 //... //自定义了Person类(有Name,Age,Heigth等属性) List<Person> ...
- PHP5.6版本安装redis扩展
一.php安装redis扩展 1.使用phpinfo()函数查看PHP的版本信息,这会决定扩展文件版本 2.根据PHP版本号,编译器版本号和CPU架构, 选择php_redis-2.2 ...
- git bash 出显错误不能用,怎么解决
解决方法: 好像就是64的会出问题,其实32位的git也可以安装在64位的系统上. 将你64位的git卸掉了后,下载一个32位的git安装,就可以正常使用了, 当然,你的32位的出了错,卸了后也这样处 ...
- String类的subString(i)方法(基于jdk 1.9)
只有一个参数的: String str = new String("ABCD"); System.out.println("str="+str.substrin ...
- 使用lock锁或Monitor.Enter的目的
锁定的目的:由于多个线程 并行/并发 处理同一个“数据对象”(比如:在其它线程的某个地方发生了Clear.Add.Remove.Change等操作),导致“数据对象”不断变化,没法用了,所以,为了保证 ...
- TileMode(平铺模式) 枚举的成员:
TileMode(平铺模式) 枚举的成员: 成员名称 说明 FlipX 与 Tile 相同,只不过图块的交替列被水平翻转. 基本图块本身不翻转. FlipXY FlipX 和 FlipY ...
- MVC 后台调用JS
示例控制器: public ActionResult Index() { ViewBag.js = "<script type='text/java ...
- hdu4347The Closest M Points kdtree
kdtree讲解: https://blog.csdn.net/qing101hua/article/details/53228668 https://blog.csdn.net/acdreamers ...
- bzoj 1798 双标记区间修改线段树
#include<bits/stdc++.h> using namespace std; #define MAXN 100000 #define M ((L+R)>>1) #d ...
- 外层页面与iframe相互调用的方法
iframe调用外层页面的方法: parent.func(); 外层页面调用里面的iframe中的内容方法: $("iframe").contents().find(" ...