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 ...
随机推荐
- Centos7 查看Mysql配置文件
my.cnf是mysql启动时加载的配置文件,一般会放在mysql的安装目录中,用户也可以放在其他目录加载. 安装mysql后,系统中会有多个my.cnf文件,有些是用于测试的. 使用locate m ...
- 机器学习tensorflow框架初试
本文来自网易云社区 作者:汪洋 前言 新手学习可以点击参考Google的教程.开始前,我们先在本地安装好 TensorFlow机器学习框架. 首先我们在本地window下安装好python环境,约定安 ...
- virtualenv简介以及一个比较折腾的scrapy安装方法
本文来自网易云社区 作者:沈高峰 virtualenv + pip 安装python软件包是一种非常好的选择,在大部分情况下安装python软件包是不需要求助于sa的. 使用自己的一个工作副本也是写p ...
- <<程序猿健康指南>> 笔记
序言: 长时间对着电脑工 作.一天下来基本不怎么走动的人,患高血压及 2 型糖尿病的风险远高于其他人群, 这两种疾病会对人体的健康产生长久的严重影响,还会增加心脏病及中风的几率. 前言: 阿米什人(A ...
- 成员变量和属性区别(@property那点事儿)
历史由来: 接触iOS的人都知道,@property声明的属性默认会生成一个_类型的成员变量,同时也会生成setter/getter方法. 但这只是在iOS5之后,苹果推出的一个新机制.看老代码时,经 ...
- leetcode 174. 地下城游戏 解题报告
leetcode 174. 地下城游戏 一些恶魔抓住了公主(P)并将她关在了地下城的右下角.地下城是由 M x N 个房间组成的二维网格.我们英勇的骑士(K)最初被安置在左上角的房间里,他必须穿过地下 ...
- CPU指令集不同导致的core分析
最近程序需要支持CGSL系统运行,测试中发现相同操作系统的两台机器,编译机运行正常,测试机coredump.core信息汇总如下,可以看出是由于测试机不支持编译后的指令导致的问题: Program t ...
- oom 和 jvm crash的问题
很多次生产环境jvm进程无故消失的时候都留下了hs_err[pid].log文件 然后通过mat分析大多数情况是oom导致的 所以以前一直认为OOM一定会导致jvm crash 也就是说java ...
- poj 1743 Musical Theme (后缀数组+二分法)
Musical Theme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 16162 Accepted: 5577 De ...
- idiots
idiots 题目描述 给定 $n$ 个长度分别为 $a_i$ 的木棒,问随机选择 $3$ 个木棒能够拼成三角形的概率. 输入格式 第一行一个正整数 nn. 第二行 nn 个正整数,第 ii 个数表示 ...