题目描述

一张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(否)。

输入输出样例

输入样例#1:

2
3 4 4 2
xx..
.xx.
xx..
x.
.x
x.
..
2 2 2 2
xx
xx
.x
x.
输出样例#1:

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的更多相关文章

  1. 洛谷 P3585 [POI2015]PIE

    P3585 [POI2015]PIE 题目描述 一张n*m的方格纸,有些格子需要印成黑色,剩下的格子需要保留白色.你有一个a*b的印章,有些格子是凸起(会沾上墨水)的.你需要判断能否用这个印章印出纸上 ...

  2. 洛谷P3585 [POI2015]PIE

    传送门 题目大意:有个n*m的格子图,要求'x'点要被染成黑色 有个a*b的印章,'x'是可以染色的印章上的点. 要求用印章去染色格子 (1)印章不可以旋转. (2)不能把墨水印到纸外面. (3)纸上 ...

  3. POI2015 解题报告

    由于博主没有BZOJ权限号, 是在洛咕做的题~ 完成了13题(虽然有一半难题都是看题解的QAQ)剩下的题咕咕咕~~ Luogu3585 [POI2015]PIE Solution 模拟, 按顺序搜索, ...

  4. POI 2018.10.20

    [POI2005]BANK-Cash Dispenser 有多少个4位字符串是所有操作序列的子串. 10^4枚举字符串.暴力判断会TLE 发现,我们就是在每个操作序列中不断找第一个出现的c字符. 预处 ...

  5. 10月清北学堂培训 Day 6

    今天是黄致焕老师的讲授~ T1 自信 AC 莫名 80 pts???我还是太菜了!! 对于每种颜色求出该颜色的四个边界,之后枚举边界构成的矩阵中每个元素,如果不等于该颜色就标记那种颜色不能最先使用. ...

  6. 【题解】PIE [POI2015] [P3585]

    [题解]\(PIE\) \([POI2015]\) \([P3585]\) 逼自己每天一道模拟题 传送门:\(PIE\) \([POI2015]\) \([P3585]\) [题目描述] 一张 \(n ...

  7. [No0000A2]“原始印欧语”(PIE)听起来是什么样子?

    "Faux Amis"节目中经常提到"原始印欧语"(PIE)——"Proto-Indo-European". 我们说过,英语,法语中的&qu ...

  8. poj3311 Hie with the Pie (状态压缩dp,旅行商)

    Hie with the Pie Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3160   Accepted: 1613 ...

  9. pygame 练习之 PIE game (以及简单图形训练)

    简单的大饼游戏,掌握pygame中直线以及圆弧的画法,以及对输入的响应. import math import pygame, sys from pygame.locals import * pyga ...

随机推荐

  1. application.properties 乱码 (已验证)

    1.打开Eclipse或MyEclipse 2.选择window-Preferences-content Types-Text-Java Properties File 3.将Java Propert ...

  2. OPC—— KepServer.ServerState返回值为3和OPCConfig.exe配置文件的根目录

    做开发没有对电脑的绝对管理员权限的问题,会出现很多意外,调试OPC是总是连接状态有时莫明返回3,提示 not configuration,问题在于: 没有以管理员权限运行OPCConfig.exe,导 ...

  3. web性能优化实践

    一.SQL查询优化 1.循环中有多次查询sql,改为在循环外一次查询后再处理 2.循环多次插入,改为组装好数据后批量插入 3.梳理业务逻辑能一次查完的,绝不分多次查 4.索引用起来 5.分页查询 二. ...

  4. Python基础(十)

    今日主要内容 补充:传参与参数分配区别 动态传参 函数注释 名称空间 函数名的使用 函数嵌套 global和nonlocal 补充:传参与参数分配区分 先看一个函数定义和函数调用 def func(a ...

  5. Linux 笔记 - 第十四章 LAMP 之(一) 环境搭建

    博客地址:http://www.moonxy.com 一.前言 LAMP 是 Linux Apache MySQL PHP 的简写,即把 Apache.MySQL 以及 PHP 安装在 Linux 系 ...

  6. ReentrantLock API

    java可重入锁,简单几个小案例,测试特性. 1.尝试锁  tryLock package com.cn.cfang.ReentrantLock; import java.util.concurren ...

  7. redis-自动补全

    自动补全实现方式有两种: 第一种:数据量非常小时,程序从redis中获取数据后,在程序中排序:redis只作为数据存储用: 第二种:数据量较大时,直接在redis中排序,并返回自动补全的数据. 第三种 ...

  8. Flask基础(13)-->Flask扩展Flask-Script

    Flask基础(12)-->Flask扩展Flask-Script # 前提是安装了Flask-Script # 联网运行 pip install flask-script from flask ...

  9. Angular 常用命令行

    1. ng -v 查看angular-cli是否安装成功.angular-cli的版本号 2. ng new 项目名称 新建angular项目 3. ng g class 类名 动态生成类文件: 4. ...

  10. PSSH工具

    目录 PSSH工具 参考 PSSH工具的介绍 PSSH工具的使用 PSSH工具