[POI2015]PIE
题目描述
一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色。你有一个a*b的印章,有些格子是凸起(会沾上墨水)的。你需要判断能否用这个印章印出纸上的图案。印的过程中需要满足以下要求:(1)印章不可以旋转。(2)不能把墨水印到纸外面。(3)纸上的同一个格子不可以印多次。
输入输出格式
输入格式:
第一行一个整数q(1<=q<=10),表示测试点数量。接下来q个测试点,每个测试点中:第一行包含4个整数n,m,a,b(1<=n,m,a,b<=1000)。接下来n行,每行m个字符,描述纸上的图案。'.'表示留白,'x'表示需要染黑。接下来a行,每行b个字符,描述印章。'.'表示不沾墨水,'x'表示沾墨水。
输出格式:
对于每个测试点,输出TAK(是)或NIE(否)。
输入输出样例
2
3 4 4 2
xx..
.xx.
xx..
x.
.x
x.
..
2 2 2 2
xx
xx
.x
x.
TAK
NIE
说明
一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色。
你有一个a*b的印章,有些格子是凸起(会沾上墨水)的。你需要判断能否用这个印章印出纸上的图案。印的过程中需要满足以下要求:
(1)印章不可以旋转。
(2)不能把墨水印到纸外面。
(3)纸上的同一个格子不可以印多次。
提交地址 : Luogu3585;
模拟水题;
调了半天(真是半天);
首先,我们肯定要把印章的左上角第一个有印的地方,对准画布上第一个左上角地方;
显然可以暴力O(n^4), T飞;
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; inline char nc()
{
static const int BS = << ;
static unsigned char buf[BS],*st,*ed;
if(st == ed) ed = buf + fread(st=buf,,BS,stdin);
return st == ed ? EOF : *st++;
}
//#define getchar nc
inline int read()
{
int res=;bool flag=;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')flag=;ch=getchar();
}while(isdigit(ch)){res=(res<<)+(res<<)+(ch-'');ch=getchar();
}return flag?-res:res;
} int q;
int n, m, x, y;
int a[][];
int tab[][];
int num, fx, fy; bool check(int xx, int yy)
{
xx -= fx - , yy -= fy - ;
for (register int i = ; i <= x ; i ++)
{
for (register int j = ; j <= y ; j ++)
{
if (tab[i][j] == ) continue;
if (xx + i - <= or xx + i - > n or yy + j - <= or yy + j - > m or a[xx+i-][yy+j-] == ) return ;
a[xx+i-][yy+j-] = ;
num--;
}
}
return ;
} int main()
{
q = read();
while (q--)
{
num=;
n=read(), m=read(), x=read(), y=read();
fx = fy = ;
for (register int i = ; i <= n ; i ++)
{
for (register int j = ; j <= m ; j ++)
{
char ch;
cin >> ch;
if (ch == '.') a[i][j] = ;
else a[i][j] = , num++;
}
}
for (register int i = ; i <= x ; i ++)
{
for (register int j = ; j <= y ; j ++)
{
char ch;
cin >> ch;
if (ch == '.') tab[i][j] = ;
else
{
tab[i][j] = ;
if (!fx) fx = i, fy = j;
}
}
} for (register int i = ; i <= n ; i ++)
{
for (register int j = ; j <= m ; j ++)
{
if (!a[i][j]) continue;
if (!check(i, j))
{
puts("NIE");
goto End;
}
if (num == )
{
puts("TAK");
goto End;
}
}
}
puts("NIE");
End:;
}
return ;
}
zZhBr
现在我们考虑优化;
我们把时间主要浪费在哪里了?
不停地循环找印章!
显然我们在印章和图里有很多不需要的点, 我们花费了太多时间浪费在它们身上;
那不如干脆来一个链表,直接把有用的点穿起来,这样查询十分省时间!
轻松A掉
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std; inline char nc()
{
static const int BS = << ;
static unsigned char buf[BS],*st,*ed;
if(st == ed) ed = buf + fread(st=buf,,BS,stdin);
return st == ed ? EOF : *st++;
}
#define nc getchar
inline int read()
{
int res=;bool flag=;char ch=nc();
while(!isdigit(ch)){if(ch=='-')flag=;ch=nc();
}while(isdigit(ch)){res=(res<<)+(res<<)+(ch-'');ch=nc();
}return flag?-res:res;
} int q;
int n, m, x, y;
struct MAP
{
int x, y;
}a[*];
int cnt = ;
struct TAB
{
int x, y;
}tab[*];
int now = ;
int mp[][]; inline bool check(int xx, int yy)
{
xx -= tab[].x - , yy -= tab[].y - ;
for (register int i = ; i <= now ; i ++)
{
int tx = xx + tab[i].x - , ty = yy + tab[i].y - ;
if (tx <= or tx > n or ty <= or ty > m) return ;
if (mp[tx][ty] == ) return ;
mp[tx][ty] = ;
}
return ;
} int main()
{
q = read();
while (q--)
{
n=read(), m=read(), x=read(), y=read();
cnt = now = ;
for (register int i = ; i <= n ; i ++)
{
for (register int j = ; j <= m ; j ++)
{
char ch;
cin >> ch;
if (ch == '.') mp[i][j] = ;
else
{
mp[i][j] = ;
a[cnt].x = i;
a[cnt++].y = j;
}
}
}
for (register int i = ; i <= x ; i ++)
{
for (register int j = ; j <= y ; j ++)
{
char ch;
cin >> ch;
if (ch == '.') continue;
else
{
tab[now].x = i;
tab[now++].y = j;
}
}
}
cnt--, now--;
for (register int i = ; i <= cnt ; i ++)
{
if (mp[a[i].x][a[i].y] == ) continue;
if (!check(a[i].x, a[i].y))
{
puts("NIE");
goto End;
}
} puts("TAK");
End:;
}
return ;
}
[POI2015]PIE的更多相关文章
- 洛谷 P3585 [POI2015]PIE
P3585 [POI2015]PIE 题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色.你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上 ...
- 洛谷P3585 [POI2015]PIE
传送门 题目大意:有个n*m的格子图,要求'x'点要被染成黑色 有个a*b的印章,'x'是可以染色的印章上的点. 要求用印章去染色格子 (1)印章不可以旋转. (2)不能把墨水印到纸外面. (3)纸上 ...
- POI2015 解题报告
由于博主没有BZOJ权限号, 是在洛咕做的题~ 完成了13题(虽然有一半难题都是看题解的QAQ)剩下的题咕咕咕~~ Luogu3585 [POI2015]PIE Solution 模拟, 按顺序搜索, ...
- POI 2018.10.20
[POI2005]BANK-Cash Dispenser 有多少个4位字符串是所有操作序列的子串. 10^4枚举字符串.暴力判断会TLE 发现,我们就是在每个操作序列中不断找第一个出现的c字符. 预处 ...
- 10月清北学堂培训 Day 6
今天是黄致焕老师的讲授~ T1 自信 AC 莫名 80 pts???我还是太菜了!! 对于每种颜色求出该颜色的四个边界,之后枚举边界构成的矩阵中每个元素,如果不等于该颜色就标记那种颜色不能最先使用. ...
- 【题解】PIE [POI2015] [P3585]
[题解]\(PIE\) \([POI2015]\) \([P3585]\) 逼自己每天一道模拟题 传送门:\(PIE\) \([POI2015]\) \([P3585]\) [题目描述] 一张 \(n ...
- [No0000A2]“原始印欧语”(PIE)听起来是什么样子?
"Faux Amis"节目中经常提到"原始印欧语"(PIE)——"Proto-Indo-European". 我们说过,英语,法语中的&qu ...
- poj3311 Hie with the Pie (状态压缩dp,旅行商)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3160 Accepted: 1613 ...
- pygame 练习之 PIE game (以及简单图形训练)
简单的大饼游戏,掌握pygame中直线以及圆弧的画法,以及对输入的响应. import math import pygame, sys from pygame.locals import * pyga ...
随机推荐
- 工业控制或办公局域网中的192.168.X.X网段
IPv4地址分为A.B.C.D.E五类,除去特殊作用的D.E两类,剩下的A.B.C三类地址是我们常见的IP地址段.A类地址的容量最大,可以容纳16777214个主机,B类地址可以容纳65534个主机, ...
- thinkphp6 常用方法文档
请求变量 use think\facade\Request; Request::param('name'); Request::param();全部请求变量 返回数组 Request::param([ ...
- Servlet实现用户登录
1.登录过程分析: 通过表单收集用户的数据,Servlet通过request对象获得用户提交的数据,服务器还需要从数据库中通过sql语句查询有没有表单提交的数据中的用户.有则登录成功,否则,登录失败. ...
- 增删改查——PreparedStatement接口
1.添加 package pers.Pre.add; import java.sql.Connection; import java.sql.DriverManager; import java.sq ...
- Linux 笔记 - 第十四章 LAMP 之(二) 环境配置
博客地址:http://www.moonxy.com 一.前言 LAMP 环境搭建好之后,其实仅仅是安装上了软件,我们还需要掌握 httpd 和 PHP 的配置. 二.httpd 配置 2.1 创建虚 ...
- Bytectf-几道web总结
1.EZcms 这道题思路挺明确,给了源码,考点就是md5哈希扩展+phar反序列化 首先这道题会在上传的文件目录下生成无效的.htaccess,从而导致无法执行上传的webshell,所以就需要想办 ...
- 05:videoToolbox:硬解码
videoToolbox:硬解码 前言:VTDecompressionSession 工作流程: 1:创建解压的会话. 2:配置会话属性. 3:解压视频帧数据. 4:释放会话.释放资源. 介绍 VT ...
- nginx主配置参数详解
########Nginx的main(全局配置)文件 #指定nginx运行的用户及用户组,默认为nobody #user nobody; #开启的线程数,一般跟逻辑CPU核数一致 worker_pro ...
- [VB.NET Tips]赋值运算千万要注意
赋值运算符是一个语句,不能在表达式中使用,表达式中的等号表示相等而不是赋值. 上示例: Dim x As Integer Dim y As Object x = 5 y = x = 5 Console ...
- SpringBoot启动zipkin-server报错Error creating bean with name ‘armeriaServer’ defined in class path resource
目前,GitHub 上最新 release 版本是 Zipkin 2.12.9,从 2.12.6 版本开始有个较大的更新,迁移使用 Armeria HTTP 引擎. 从此版本开始,若直接添加依赖的 S ...