Rectangles POJ 3695
来源:互联网 发布:掌趣上游网络牟正文 编辑:程序博客网 时间:2024/05/29 04:10
这道题n比较小,可以用容斥原理来做
好像直接扫描线也可以
把所有查询的状态用二进制存起来,然后用dfs进行容斥,对于每个状态,找到其是哪个查询容斥项,把面积加上去
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int inf=1000001;struct Rectangle{ int x1,x2,y1,y2;};Rectangle rc[25];int n,m;int ask[100005];int area[1<<20];void dfs(int x1,int y1,int x2,int y2,int deep,int flag,int sta){//才发现原来矩形求交这么简单 if(x1>=x2 || y1>=y2) return;//没有公共面积 if(deep==n){ if(sta) { for(int i=0;i<m;i++){//找到所有包含该状态的查询 if ((ask[i]|sta)==ask[i]){ area[ask[i]]+=flag*(x2-x1)*(y2-y1); } } } return; } dfs(x1,y1,x2,y2,deep+1,flag,sta); dfs(max(x1,rc[deep].x1),max(y1,rc[deep].y1),min(x2,rc[deep].x2),min(y2,rc[deep].y2),deep+1,-flag,sta|(1<<deep)); //n个矩形的公共面积只要找最上的下界,最右的左界,最下的上界,最左的右界}int main(){ #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int cas=0; while(scanf("%d%d",&n,&m)!=EOF,n+m){ memset(area,0,sizeof(area)); memset(ask,0,sizeof(ask)); for(int i=0;i<n;i++) scanf("%d%d%d%d",&rc[i].x1,&rc[i].y1,&rc[i].x2,&rc[i].y2); for(int i=0;i<m;i++){ int t,x; scanf("%d",&t); for(int j=0;j<t;j++) { scanf("%d",&x); ask[i]|=1<<(x-1); } } dfs(0,0,inf,inf,0,-1,0); printf("Case %d:\n", ++cas); for(int i = 0; i < m; i++) printf("Query %d: %d\n", i+1, area[ask[i]]); printf("\n"); } return 0;}
0 0
- Rectangles POJ 3695
- POJ 3695 Rectangles 笔记
- POJ 3695 Rectangles(矩形切割)
- poj 3695 Rectangles(矩形切割)
- Rectangles - POJ 3695 容斥原理
- POJ 3695 Rectangles(容斥)
- poj 3695 Rectangles(容斥原理)
- poj 1468 Rectangles
- poj 1468 Rectangles
- poj 1693 Counting Rectangles
- POJ 1468 Rectangles
- POJ 1468 Rectangles 笔记
- POJ 1314 Finding Rectangles
- poj 3695 Rectangles 容斥原理解矩形面积并
- zoj 1139 || poj 1468 Rectangles
- POJ 1314 Finding Rectangles 笔记
- HDU-1796 How many integers can you find || POJ-3695 Rectangles || POJ-3904 Sky Code
- Rectangles
- POJ 3321 Apple Tree( 树状数组)
- Python-Notes-1: append VS extend
- 学术休假期间作业——银行储蓄系统(基础版)
- 寒假刷oj——简易计算器
- 春节假期全民疯抢电子红包 程序员表示“压力山大”
- Rectangles POJ 3695
- 【Jason's_ACM_解题报告】Stacks of Flapjacks
- Android-root 破解原理分析
- POJ 题目1258 Agri-Net(最小生成树)
- poj 2452 RMQ(Sticks Problem)
- web服务器并发访问如何提升
- 同步异步
- 360与百度研发工程师的待遇,工作环境全面对比
- hdu 1394(线段树)