hdu 2461(AC) & poj 3695(TLE)(离散化+矩形并)
Rectangles
Time Limit: 5000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1503 Accepted Submission(s): 777
are developing a software for painting rectangles on the screen. The
software supports drawing several rectangles and filling some of them
with a color different from the color of the background. You are to
implement an important function. The function answer such queries as
what is the colored area if a subset of rectangles on the screen are
filled.
input consists of multiple test cases. Each test case starts with a
line containing two integers N(1 ≤ N ≤ 20) and M(1 ≤ M ≤ 100000),
indicating the number of rectangles on the screen and the number of
queries, respectively.
The i-th line of the following N lines
contains four integers X1,Y1,X2,Y2 (0 ≤ X1 < X2 ≤ 1000, 0 ≤ Y1 <
Y2 ≤ 1000), which indicate that the lower-left and upper-right
coordinates of the i-th rectangle are (X1, Y1) and (X2, Y2). Rectangles
are numbered from 1 to N.
The last M lines of each test case describe
M queries. Each query starts with a integer R(1<=R ≤ N), which is
the number of rectangles the query is supposed to fill. The following
list of R integers in the same line gives the rectangles the query is
supposed to fill, each integer of which will be between 1 and N,
inclusive.
The last test case is followed by a line containing two zeros.
For
each query in the input, print a line containing the query number
(beginning with 1) followed by the corresponding answer for the query.
Print a blank line after the output for each test case.
0 0 2 2
1 1 3 3
1 1
2 1 2
2 1
0 1 1 2
2 1 3 2
2 1 2
0 0
Query 1: 4
Query 2: 7
Case 2:
Query 1: 2
///离散化
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <cmath>
using namespace std;
const int N = ;
struct Rec
{
int x1,y1,x2,y2;
} rec[N];
int x[N*],y[N*];
int vis[N*][N*];
int k,n,t,m;
int binary1(int l,int r,int value)
{
int mid;
while(l<r)
{
mid = (l+r)>>;
if(x[mid]==value) return mid;
if(x[mid]<value) l = mid+;
else r = mid-;
}
return l;
}
int binary2(int l,int r,int value)
{
int mid;
while(l<r)
{
mid = (l+r)>>;
if(y[mid]==value) return mid;
if(y[mid]<value) l = mid+;
else r = mid-;
}
return l;
}
int k1,k2;
void input()
{
k=,t=;
int x1,y1,x2,y2;
for(int i=; i<n; i++)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
rec[t].x1 = x1,rec[t].y1 = y1,rec[t].x2=x2,rec[t++].y2 = y2;
x[k] = x1,y[k++] = y1;
x[k] = x2,y[k++] = y2;
}
sort(x,x+k);
sort(y,y+k);
k1 = ,k2=;
x[k1] = x[];
y[k2] = y[];
for(int i=;i<k;i++){ ///去重还是TLE
if(x[i]!=x[i-]) x[++k1] = x[i];
if(y[i]!=y[i-]) y[++k2] = y[i];
}
}
int solve(int num)
{
memset(vis,,sizeof(vis));
while(num--)
{
int b;
scanf("%d",&b);
int t1,t2,t3,t4;
t1 = binary1(,k1,rec[b-].x1);
t2 = binary1(,k1,rec[b-].x2);
t3 = binary2(,k2,rec[b-].y1);
t4 = binary2(,k2,rec[b-].y2);
for(int j=t1; j<t2; j++)
{
for(int l = t3; l<t4; l++)
{
vis[j][l] = ;
}
}
}
int area = ;
for(int i=; i<=k1; i++)
{
for(int j=; j<=k2; j++)
{
area+=vis[i][j]*(x[i+]-x[i])*(y[j+]-y[j]);
}
}
return area;
}
int main()
{
int x1,y1,x2,y2;
int cnt = ;
while(scanf("%d%d",&n,&m)!=EOF&&n+m)
{ input();
int a,b;
printf("Case %d:\n",cnt++);
int cas = ;
while(m--)
{
scanf("%d",&a);
printf("Query %d: %d\n",cas++,solve(a));;
}
printf("\n");
}
return ;
}
hdu 2461(AC) & poj 3695(TLE)(离散化+矩形并)的更多相关文章
- hdu 2896 AC自动机
// hdu 2896 AC自动机 // // 题目大意: // // 给你n个短串,然后给你q串长字符串,要求每个长字符串中 // 是否出现短串,出现的短串各是什么 // // 解题思路: // / ...
- hdu 3065 AC自动机
// hdu 3065 AC自动机 // // 题目大意: // // 给你n个短串,然后给你一个长串,问:各个短串在长串中,出现了多少次 // // 解题思路: // // AC自动机,插入,构建, ...
- hdu 4057 AC自己主动机+状态压缩dp
http://acm.hdu.edu.cn/showproblem.php?pid=4057 Problem Description Dr. X is a biologist, who likes r ...
- HDU 1815, POJ 2749 Building roads(2-sat)
HDU 1815, POJ 2749 Building roads pid=1815" target="_blank" style="">题目链 ...
- hdu 5880 AC自动机
Family View Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2296 aC自动机+dp(得到价值最大的字符串)
Ring Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3065 AC自动机(各子串出现的次数)
病毒侵袭持续中 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
随机推荐
- 8 定制10MINs 3
1. <div class="ui inverted red basic segment"> <h3 class="ui header"> ...
- bootstrap重新设计按钮样式
1.将btn的样式换成以下的样式 2.思路: (1)将原来的btn样式设置color:#FFF,同时text-shadow设置,这样原来的btn样式就会变淡了,后面再加上新的样式就可以覆盖掉 注意:要 ...
- X-Frame-Options是什么?
错误: Refused to display 'http://xx.com/spot/kline.do' in a frame because it set 'X-Frame-Options' to ...
- 转载: keepalived工作原理和配置说明
转自:http://outofmemory.cn/wiki/keepalived-configuration keepalived是什么 keepalived是集群管理中保证集群高可用的一个服务软件, ...
- 《Cracking the Coding Interview》——第3章:栈和队列——题目4
2014-03-18 05:28 题目:你肯定听过汉诺威塔的故事:三个柱子和N个从小到大的盘子.既然每次你只能移动放在顶上的盘子,这不就是栈操作吗?所以,请用三个栈来模拟N级汉诺威塔的玩法.放心,N不 ...
- 《数据结构》C++代码 栈与队列
线性表中,先进先出的叫队列,先进后出的叫栈.队列常用于BFS,而在函数递归层数过高时,需要手动实现递归过程,这时候便需要写一个“手动栈”. 有时候,我们会有大量数据频繁出入队列,但同时存在其内的元素却 ...
- iOS笔记056 - UI总结02
九宫格布局 UICollectionViewController 创建控制器一定要指定默认的布局样式. // 加载一个九宫格布局的控制器,必须指定布局样式 UICollectionViewFlowLa ...
- 聊聊、Git 常用命令
创建本地仓库git initgit add .git commit -m "xxxxx"git remote add origin http://git.xxx.com/xxx.g ...
- springboot11 JPA
一.JPA 1. JPA 介绍 JPA是Java Persistence API的简称,中文名Java持久层API,是JDK 5.0注解或XML描述对象-关系表的映射关系,并将运行期的实体对象持久化到 ...
- ASP.NET Core MVC 运行所选代码生成器时出错
添加Nuget Microsoft.VisualStudio.Web.CodeGeneration.Design Microsoft.EntityFrameworkCore.Tools