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 ...
随机推荐
- WPF在ViewModel中绑定按钮点击(CommandBase定义)
定义CommandBase public class CommandBase:ICommand { private readonly Action<object> _commandpara ...
- linux文件重命名
rename 命令用字符串替换的方式批量改变文件名. 语法 rename(参数) 参数 原字符串:将文件名需要替换的字符串: 目标字符串:将文件名中含有的原字符替换成目标字符串: 文件:指定要改变文件 ...
- tarjan求强连通分量的思考
我是按照这里的思路来的.这个博文只是感性理解. 递归树 关于递归树,这篇博文讲的很好,我只是给自己总结一下. 定义vis数组,在dfs连通图时赋予它们不同的含义: vis=0,表示这个点没有被访问. ...
- 洛谷P1633 二进制
P1633 二进制 题目描述 有三个整数A.B.C,以下用N(2)表示N的二进制(没有前导0). 设A(2).B(2).C(2)的最大长度为L,你需要构造三个正整数X.Y.Z,满足以下条件: (1) ...
- spring框架_IOC与注解
1.什么是IOC? IoC(Inverse Of Control:反转控制) 2.IOC的作用是什么? 削减计算机程序的耦合(解除我们代码中的依赖关系). 3.关于程序的耦合 /** * 程序的耦合 ...
- php对数组操作的函数
array_reverse 以相反的顺序返回数组 array_unique 数组元素去重(只对一维数组有效) array_intersect两个或多个数组取交集 implode和explode也 ...
- A-坐飞机
链接:https://ac.nowcoder.com/acm/contest/892/A 题意: 鸡尾酒要去很多很多地方玩,于是他一次买了 n 张机票,初始鸡尾酒在第一个城市,对于任意的i(1≤i≤n ...
- Yii2.0权限系统,使用PhpManager的方式
网上搜了一大堆yii2.0权限系统,大抵都是千篇一律,而且基本上都是DbManager.看了半天官方文档之后,终于知道了PhpManager的方式下,是怎么引入权限系统.介绍下我自己的使用.首先,配置 ...
- build spark
Error : Failed to find Spark jars directory (/home/pl62716/spark-2.2.0-SNAPSHOT/assembly/target/scal ...
- java中存储金额
很早之前, 记得一次面试, 面试官问存储金钱用什么数据类型? 当时只知道8种数据类型(boolean, byte, short, int, long, float, double, char)的我, ...