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 ...
随机推荐
- Retrofit get post query filed FiledMap
直接请求型 1.如果是直接请求某一地址,写法如下: @GET("/record") Call getResult(); 2.如果是组合后直接请求,如/result/{id}写法如下 ...
- 如何在react里嵌入iframe?
无法访问iframe地址 index.js文件 import React from 'react'; import ReactDOM from 'react-dom'; import App from ...
- Thread-local storage (TLS)
线程存储原理:为变量在每一个现存的线程里分配一个实例,需要处理器支持,并不是所有都支持!支持全局的,静态的变量,但不支持局部变量. 关键字 __thread __thread int i; e ...
- MySQL 5.7.18 压缩包版配置记录
1.解压到一个目录(建议根目录),比如:D:\mysql2.在系统Path中添加 D:\mysql\bin3.这个版本不带my-default.ini,需要自己写,放在D:\mysql\my.ini, ...
- (原)SpringMVC全注解不是你们那么玩的
前言:忙了段时间,忙得要死要活,累了一段时间,累得死去活来. 偶尔看到很多零注解配置SpringMVC,其实没有根本的零注解. 1)工程图一张: web.xml在servlet3.0里面已经被注解完全 ...
- python selenium 练习 自动获取豆瓣阅读当前特价书籍 chrome 元素定位 窗口切换 元素过期
豆瓣原创电子书每周推出数十本限时免费数目,一周免费期过后恢复原价.想着豆瓣原创书中有不少值得一看,便写了个脚本,免去一个个添加的烦恼. 使用了Windows下selenium+Python的组合,有较 ...
- css深入理解padding
padding 中规中矩,性格温婉平和! 第一节:CSS padding与容器的尺寸——了解padding与元素尺寸之间关系 CSS padding与容器的尺寸关系复杂 对于block水平元素 没有p ...
- 【转】Unity3D研究院之设置自动旋转屏幕默认旋转方向
http://www.xuanyusong.com/archives/2871 如下图所示,在处理屏幕默认旋转方向的时候可以在这里进行选择,上下左右一共是4个方向. 策划的需求是游戏采用横屏,但是要求 ...
- HTML5_纯JS实现上传文件显示文件大小,文件信息,上传进度_不使用JS库
前台 html <input type="file" id="_netLogo" onchange="fileSelected();" ...
- hdu 2544 最短路 (最短路径)
最短路 Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...