E - Polycarp and Snakes
题意:在一个全是点的图上开始画线,每次将一行或一列任意长度染成字母,一笔染一种字母,字母必须从a开始连续到后面某个字母可以覆盖。
问所给图案是否满足 ,若满足输出它画了几个字母,然后输出这每个字母开始和截止画的横纵坐标。
思路:存图,模拟,用个x1,x2,y1,y2记录每个字母出现位置的最小最大的横纵坐标,对于每个字母如果它的x1,x2,y1,y2不是初始值的话,那么它在图上就出现过(没有被覆盖掉),那么这个字母必然满足,x1==x2||y1==y2;
#include<bits/stdc++.h>
using namespace std;
char mp[][];
int x1[],x2[],y1[],y2[]; int main()
{
int n,m;
int it=;
scanf("%d",&it);
while(it--)
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
scanf("%s",mp[i]+);
for(int i=; i<=; i++)
{
x1[i]=;
y1[i]=;
x2[i]=-;
y2[i]=-;
}
for(int i=; i<=n; i++)
for(int j=; j<=m; j++)
{
if(mp[i][j]!='.')
{
int num=mp[i][j]-'a'+;
x1[num]=min(x1[num],i);
x2[num]=max(x2[num],i);
y1[num]=min(y1[num],j);
y2[num]=max(y2[num],j);
}
}
int flag=;
int live[];
int cnt=;
memset(live,,sizeof(live));
for(int i=; i<=; i++)
{
if(x1[i]!=&&y1[i]!=)
{
if(x1[i]==x2[i])
{
cnt=i;
for(int j=y1[i]; j<=y2[i]; j++)
if(mp[x1[i]][j]<('a'+i-))
{
flag=;
break;
}
live[i]=;
}
else if(y1[i]==y2[i])
{
cnt=i;
for(int j=x1[i]; j<=x2[i]; j++)
{
if(mp[j][y1[i]]<('a'+i-))
{
flag=;
break;
}
}
live[i]=;
}
else
{
flag=;
break;
}
}
}
// for(int i=1; i<=5; i++)
// printf("%d %d %d %d\n",x1[i],x2[i],y1[i],y2[i]);
if(flag==)
printf("NO\n");
else
{
printf("YES\n%d\n",cnt);
for(int i=; i<=cnt; i++)
{
if(live[i]==)
{
// printf("???");
for(int j=i+; j<=; j++)
{
if(live[j]==)
{
printf("%d %d %d %d\n",x1[j],y1[j],x2[j],y2[j]);
break;
}
}
}
else
printf("%d %d %d %d\n",x1[i],y1[i],x2[i],y2[i]);
}
}
}
}
E - Polycarp and Snakes的更多相关文章
- Codeforces Round #568 (Div. 2) 选做
A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...
- cf723c Polycarp at the Radio
Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...
- codeforces 723C : Polycarp at the Radio
Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...
- Codeforces 723C. Polycarp at the Radio 模拟
C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- Codeforces Round #375 (Div. 2) C. Polycarp at the Radio 贪心
C. Polycarp at the Radio time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #346 (Div. 2) F. Polycarp and Hay 并查集
题目链接: 题目 F. Polycarp and Hay time limit per test: 4 seconds memory limit per test: 512 megabytes inp ...
- [POJ 2588] Snakes
同swustoj 8 Snakes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1015 Accepted: 341 ...
- [POJ 2588]--Snakes(并查集)
题目链接:http://poj.org/problem?id=2588 Snakes Time Limit: 1000MS Memory Limit: 65536K Description B ...
- Polycarp's problems
Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 程序员必备,C#各类项目、开源项目插件资料收藏
一.AOP框架 Encase 是C#编写开发的为.NET平台提供的AOP框架.Encase独特的提供了把方面(aspects)部署到运行时代码,而其它AOP框架依赖配置文件的方式.这种部署方面 ...
- Flask RESTful API搭建笔记
之前半年时间,来到项目的时候,已经有一些东西,大致就是IIS+MYSQL+PHP. 所以接着做,修修补补,Android/iOS与服务器数据库交换用PHP, Web那边则是JS+PHP,也没有前后端之 ...
- RVO算法
http://blog.sina.com.cn/s/blog_6ad33d350102xqal.html 简介 在介绍VO,RVO之前,需要先介绍路径规划. 对Agent进行路径规划,实际上要完成的任 ...
- [转] 深度探索Hyperledger技术与应用之超级账本的典型交易流程
转自: https://blog.csdn.net/HiBlock/article/details/80212499 个人感觉对交易流程描述的比较清楚,转载以备查看. 1 典型交易流程 下图所示为Hy ...
- 洛谷P3645 [APIO2015]雅加达的摩天楼(最短路+分块)
传送门 这最短路的建图怎么和网络流一样玄学…… 一个最朴素的想法是从每一个点向它能到达的所有点连边,边权为跳的次数,然后跑最短路(然而边数是$O(n^2)$除非自创复杂度比spfa和dijkstra还 ...
- IT兄弟连 JavaWeb教程 AJAX中参数传递问题
使用Ajax发送GET请求并需要传递参数时,直接在URL地址后拼接参数,格式如下: xhr.open('get','请求路径?参数名1=参数值1&参数名2=参数值2...',true); 使用 ...
- docker网络设置(待整理)
手动指定容器的配置 -h HOSTNAME or --hostname=HOSTNAME \\设定容器的主机名. --dns=IP_ADDRESS \\指定DNS地址. ...
- linux设置重启
crontab -e 0 6 * * * reboot service crond restart
- [Java]基本数据类型及其封装类总结
九种基本数据类型的大小,以及他们的封装类 类型 字节 默认值 封装类 byte 1 0 Byte char 2 null Character int 4 0 Integer long 8 0 Long ...
- CodeForces - 603A-Alternative Thinking (思维题)
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO ...