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. [poj百练]2754:八皇后 回溯

    描述 会下国际象棋的人都很清楚:皇后可以在横.竖.斜线上不限步数地吃掉其他棋子.如何将8个皇后放在棋盘上(有8 * 8个方格),使它们谁也不能被吃掉!这就是著名的八皇后问题. 对于某个满足要求的8皇后 ...

  2. 前端需要了解的http知识

    一.五层协议1. OSI(Open System Interconnection 开放式系统互联)七层协议 1)应用层 2)表示层 3)会话层 4)传输层 5)网络层 6)数据链接层 7)物理层2. ...

  3. RenderTexture

    https://docs.unity3d.com/Manual/class-RenderTexture.html Size: 图片像素尺寸,这个size可以直接在脚本里通过width和height动态 ...

  4. solidity 学习笔记(5)接口

    接口:不用实现方法,仅仅定义方法. pragma solidity ^; contract cat{ //cat实际上实现了接口animalEat,因为他们有相同的方法. string name; f ...

  5. [Xcode 实际操作]六、媒体与动画-(7)遍历系统提供的所有滤镜

    目录:[Swift]Xcode实际操作 本文将演示系统到底提供了多少滤镜供开发者使用,并了解每个滤镜都有哪些参数需要配置. 在项目导航区,打开视图控制器的代码文件[ViewController.swi ...

  6. 剑指Offer的学习笔记(C#篇)-- 求1+2+3+...+n

    题目描述 求1+2+3+...+n,要求不能使用乘除法.for.while.if.else.switch.case等关键字及条件判断语句(A?B:C). 一 . 直接解题吧 芽儿呦,突然觉得,我不说! ...

  7. 使用tcpdump抓取EOS帐户创建与交易数据

    基本环境配置 EOS 版本:1.0.1(2018-06-04更新)   节点nodeos http监听端口:127.0.0.1:8888 本地钱包keosd http监听端口:127.0.0.1:89 ...

  8. idea 添加yuicompressor压缩js/css

    打开idea 点击file->Settings 出现如下界面 argumets项填写 : -jar F:\yui\yuicompressor-2.4.8.jar $FilePath$ -o $F ...

  9. C# Monitor与线程同步

    Monitor对象(C#知识点总结系列:4.C#中Monitor和Lock以及区别) 1.Monitor.Enter(object)方法是获取锁,Monitor.Exit(object)方法是释放锁, ...

  10. Educational Codeforces Round 66 (Rated for Div. 2) A. From Hero to Zero

    链接:https://codeforces.com/contest/1175/problem/A 题意: You are given an integer nn and an integer kk. ...