POJ 3695 Rectangles(容斥)
来源:互联网 发布:linux nvidia 驱动 编辑:程序博客网 时间:2024/06/05 21:49
题意:
n个矩阵m次访问,求每次访问的总面积
参考http://http://blog.csdn.net/sdj222555/article/details/7983902
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>using namespace std;#define MAXN 111111#define inf 100000011int ask[MAXN],st[1111111];int n,m;struct Rec{ int x1,x2,y1,y2;}p[22];void dfs(int xa,int ya, int xb, int yb, int deep, int flag ,int sta){if(xa>=xb || ya>=yb) return;if(deep==n){if(sta){for(int i=1;i<=m;i++){if((ask[i]|sta)==ask[i])st[ask[i]] += flag*(xb-xa)*(yb-ya);}}return;}dfs(xa,ya,xb,yb,deep+1,flag,sta);dfs(max(xa,p[deep+1].x1),max(ya,p[deep+1].y1),min(xb,p[deep+1].x2),min(yb,p[deep+1].y2),deep+1,-flag,sta|(1<<deep));}int in(){ char ch; int a = 0; while((ch = getchar()) == ' ' || ch == '\n'); a += ch - '0'; while((ch = getchar()) != ' ' && ch != '\n') { a *= 10; a += ch - '0'; } return a;}int main(){int cas=1;while(cin>>n>>m){if(n==0 && m==0) break;memset(st,0,sizeof(st));memset(ask,0,sizeof(ask));for(int i=1;i<=n;i++){scanf("%d%d%d%d", &p[i].x1, &p[i].y1, &p[i].x2, &p[i].y2);}int t,x;for(int i=1;i<=m;i++){t = in();while(t--){x = in();ask[i] |= (1<<(x-1));}}dfs(0,0,inf,inf,0,-1,0);printf("Case %d:\n",cas++);for(int i=1;i<=m;i++){printf("Query %d: %d\n",i,st[ask[i]]);}printf("\n");}return 0;}
0 0
- POJ 3695 Rectangles(容斥)
- Rectangles - POJ 3695 容斥原理
- poj 3695 Rectangles(容斥原理)
- HDU-2461 Rectangles(容斥原理)
- hdu2461 Rectangles-----容斥
- poj 3695 Rectangles 线段树扫描线 or 容斥原理
- POJ 3695 Rectangles 1w询问求20个矩阵面积并 容斥
- POJ 3695 Rectangles (矩形并 状压+容斥定理 好题)
- hdu-2461-Rectangles(容斥)
- poj 3695 Rectangles(矩形切割)
- Rectangles POJ 3695
- POJ 3695 Rectangles 笔记
- HDU 2461 Rectangles 容斥原理
- [容斥原理] hdu 2461 Rectangles
- POJ 3695 Rectangles(矩形切割)
- POJ 3904(容斥原理)
- POJ 2773 Happy 2006 (容斥)
- POJ 3904 Sky Code(容斥)
- iOS 表视图控件当存在导航栏与Tabbar时内容的自动偏移
- 【C++】纯虚函数的简单应用。
- Leetcode Sum Root to Leaf Numbers
- cogs 859 数列【线段树】
- 【leetcode】Flatten Binary Tree to Linked List
- POJ 3695 Rectangles(容斥)
- 如何在win7中使用IIS和花生壳搭建简单服务器
- 使用jekyll在github上搭建静态博客
- 【面试题】-判断单链表是否有环并找到环入口(快慢指针)
- 分治算法 求数组逆序数
- 适配器模式
- Lex学习笔记
- MyBatis学习一--介绍与架构
- BFS —— POJ 3278 Catch That Cow