[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 ...
随机推荐
- 用101000张食物图片实现图像识别(数据的获取与处理)-python-tensorflow框架
前段时间,日剧<轮到你了>大火,作为程序员的我,看到了另外一个程序员—二阶堂,他的生活作息,以及饮食规律,让我感同身受,最让我感触的是他做的AI聊天机器人,AI菜品分析机器人,AI罪犯分析 ...
- Hola!
个人资料 我叫Xenny,当然我还有很多名字,Tony.LTY.唐梦寒.soar.tafhack等等,这些都是我的昵称:但是用的最多的还是Xenny. Xenny的来历很扯,Xen是因为从XD中取了个 ...
- TestNG(十三) 参数化测试(DataProvider)
package com.course.testng.Parameter; import org.testng.annotations.DataProvider; import org.testng.a ...
- 01 jvm学习过程概述
声明:本博客仅仅是一个初学者的学习记录.心得总结,其中肯定有许多错误,不具有参考价值,欢迎大佬指正,谢谢!想和我交流.一起学习.一起进步的朋友可以加我微信Liu__66666666 这是简单学习一遍之 ...
- 在.NET Core中使用DispatchProxy“实现”非公开的接口
原文地址:"Implementing" a non-public interface in .NET Core with DispatchProxy 原文作者:Filip W. 译 ...
- 基于SpringBoot实现AOP+jdk/CGlib动态代理详解
动态代理是一种设计模式.在Spring中,有俩种方式可以实现动态代理--JDK动态代理和CGLIB动态代理. JDK动态代理 首先定义一个人的接口: public interface Person { ...
- Spring Boot (五): Redis缓存使用姿势盘点
1. Redis 简介 Redis 是目前业界使用最广泛的内存数据存储.相比 Memcached,Redis 支持更丰富的数据结构,例如 hashes, lists, sets 等,同时支持数据持久化 ...
- 【译】Kubernetes监控实践(2):可行监控方案之Prometheus和Sensu
本文介绍两个可行的K8s监控方案:Prometheus和Sensu.两个方案都能全面提供系统级的监控数据,帮助开发人员跟踪K8s关键组件的性能.定位故障.接收预警. 拓展阅读:Kubernetes监控 ...
- Mybatis逆向工程过程中出现targetRuntime in context mybatisGenerator is invalid
最开始设置的Mybatis,但是逆向工程准备就绪后出现问题 报错为targetRuntime in context mybatisGenerator is invalid 后来修改为Mybatis3能 ...
- JSP常规内容
1.forword和redirect的区别? forword是服务器请求资源,服务器直接读取URL,把目标地址URL响应读取出来,然后再把这些内容发送给浏览器.(特点是url和request sess ...