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

  1. Codeforces Round #568 (Div. 2) 选做

    A.B 略,相信大家都会做 ^_^ C. Exam in BerSU 题意 给你一个长度为 \(n\) 的序列 \(a_i\) .对于每个 \(i\in [1,N]\) 求 \([1,i-1]\) 中 ...

  2. cf723c Polycarp at the Radio

    Polycarp is a music editor at the radio station. He received a playlist for tomorrow, that can be re ...

  3. codeforces 723C : Polycarp at the Radio

    Description Polycarp is a music editor at the radio station. He received a playlist for tomorrow, th ...

  4. Codeforces 723C. Polycarp at the Radio 模拟

    C. Polycarp at the Radio time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...

  5. 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 ...

  6. 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 ...

  7. [POJ 2588] Snakes

    同swustoj 8 Snakes Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1015   Accepted: 341 ...

  8. [POJ 2588]--Snakes(并查集)

    题目链接:http://poj.org/problem?id=2588 Snakes Time Limit: 1000MS   Memory Limit: 65536K   Description B ...

  9. Polycarp's problems

    Polycarp's problems time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. js读取excel中日期格式转换问题

    在使用js-xlsx插件来读取excel时,会将2018/10/16这种数据自动装换成48264.12584511. 所以需要自己手动再转换回来 // excel读取2018/01/01这种时间格式是 ...

  2. svn git 的区别(别再问我了)

    这篇主要是谈谈两者的区别,至于谁优谁劣看官自己思考吧! 把第一条理解到位思想到位了做起来才会有的放矢,其他几条都是用的时候才能体会到 1) 最核心的区别Git是分布式的,而Svn不是分布的.能理解这点 ...

  3. react父组件调用子组件方法

    把子组件的参数回传到父组件中,并且赋值给子组件的一个实例方法. 参考React中文网: http://www.css88.com/react/docs/refs-and-the-dom.html im ...

  4. C.One Piece

    链接:https://ac.nowcoder.com/acm/contest/908/C 题意: Luffy once saw a particularly delicious food, but h ...

  5. NET Core中使用Apworks

    NET Core中使用Apworks HAL,全称为Hypertext Application Language,它是一种简单的数据格式,它能以一种简单.统一的形式,在API中引入超链接特性,使得AP ...

  6. java preparement

    1.建立链接 Connection conn = getDataSource().getConnection(); PreparedStatement ps = null; 2不自动 Commit 不 ...

  7. jQuery 数字滚动插件

    这几天闲来没事写的,有不对的地方还请多多指点 CSS: ; padding:0 2px;} .digital-beating i {;; background:url(../images/icon_0 ...

  8. java join 方法的使用

    在很多情况下,主线程创建并启动子线程,如果子线程中要进行大量的耗时运算,主线程往往将早于子线程结束之前结束.这时,如果主线程想等待子线程执行完成之后再结束,比如子线程处理一个数据,主线程要取得这个数据 ...

  9. Css+Html

    CSS样式 <style type="text/css"> tt.tt1 { <style type="text/css"> p { b ...

  10. Spring Boot 集成 PageHelper

    配置一:在 [pom.xml] 文件中引入依赖 <!-- mybatis的分页插件 --> <dependency> <groupId>com.github.pag ...