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 ...
随机推荐
- Atom使用插件精选(FE)
[转]原文https://zhuanlan.zhihu.com/p/24753739?refer=AlenQi Atom琳琅满目的插件中,为前端coder推荐一些实用的插件. sync-setting ...
- 开启虚拟机所报的错误:VMware Workstation cannot connect to the virtual machine. Make sure you have rights to run the program, access all directories the program uses, and access all directories for temporary fil
当我们开启虚拟机时出现错误: VMware Workstation cannot connect to the virtual machine. Make sure you have rights t ...
- ElasticSearch学习笔记(五)-- 排序、分页与遍历
1. 相关性算分 这样能够查询到不同分片上的文档的准确算分,默认分片为5 2. sorting-doc-values-fielddata 3. 分页与遍历
- python学习笔记四:lambda表达式和switch
一.定义 lambda arg1,arg2... : returnValue 二.示例 #!/usr/bin/python def f(x,y): return x*y print f(2,3) g ...
- 图的最短路径:Dijkstra 和 Floyd
//最短路径 /* dijkstra Dijkstra(迪杰斯特拉)算法的核心思想是贪心策略+动态规划 http://www.programgo.com/article/4721147659/ Dij ...
- CSS UNIT 详解以及最佳实践
分类 ■ 绝对长度(Absolute units):cm,mm,in,pt,pc 绝对单位之间的换算:1in = 2.54cm=25.4mm=72pt=6pc 绝对长度在css中的表现和其他地方 ...
- Wordpress 后台文章编辑区添加模板选择功能
功能:后台编辑文章时,可以选择文章使用的模板,效果如下图: 操作步骤: <?php /** * Template Name: kbsingle full * Add by Ryan 3/18/2 ...
- 放映PPT幻灯片演示文稿如何让演讲者备注不投影到屏幕上(转载)
ps files/ps.rar 放映PPT幻灯片演示文稿如何让演讲者备注不投影到屏幕上 如题,在PPT幻灯片的演示文稿中加入演讲者备注(使用PPT讲座时苦于有时会忘记一些要讲的数字,文字等),但是在 ...
- 深入理解css之float
1.float的历史 float的设计的初衷:文字环绕效果 2.包裹与破坏 增强浮动的感性认知 包裹:1.收缩 2.坚挺 3.隔绝 里面的布局和外面一点关系都没有 包裹的特性就是BFC block f ...
- hdu2010(dfs+剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...