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# ConfigurationManager 类的使用
一.前言 在项目中,我们习惯使用 ConfigurationManager 来读取一些常量.如链接数据库字符串.一些需配置的数据(微信.QQ.支付宝)等的配置.我们需要把这些数据记录在 app.con ...
- VS~通过IIS网站启用"域名"调试
在我们开发网站时,对某些信息进行序列化时,通常使用session,cookies,nosql等技术,而为了安全,我们在服务器上很多情况都做了防止盗链的设计,这给本机调试带来了不便,因为,本机都是以lo ...
- solidity 学习笔记(6)call 函数
call() 方法 call()是一个底层的接口,用来向一个合约发送消息,也就是说如果你想实现自己的消息传递,可以使用这个函数.函数支持传入任意类型的任意参数,并将参数打包成32字节,相互拼接后向合约 ...
- Candies
Candies Time Limit: 1500MS Memory Limit: 131072K Total Submissions: 30247 Accepted: 8409 Descrip ...
- css布局知识点汇总
昨天早上看到了一篇很棒的文章,这篇文章将布局的一些知识点整理的很不错.我也想整理一下,这样在以后的项目中可以活学活用,避免只用一种方式. 参考文章:https://segmentfault.com/a ...
- 剑指Offer的学习笔记(C#篇)-- 构建乘积数组
题目描述 给定一个数组A[0,1,...,n-1],请构建一个数组B[0,1,...,n-1],其中B中的元素B[i]=A[0]*A[1]*...*A[i-1]*A[i+1]*...*A[n-1].不 ...
- 洛谷P2169 正则表达式
题目背景 小\(Z\)童鞋一日意外的看到小\(X\)写了一个正则表达式的高级程序,这个正则表达式程序仅仅由字符"\(0\)","\(1\)","\(. ...
- [题解]luogu_P2155_BZOJ_2186沙拉公主的困惑
题意求1~N!中与M!互质的数的个数, 首先证明gcd(a,b)=1时gcd(a-kb,b)=1 gcd(a,b)=1 gcd(a%b,b)=1 gcd(a-kb,b)=1 即a-kb与b互质 这样由 ...
- css3椭圆运动
通过使用css3实现让元素椭圆运动.而不是圆形运动. 效果1:http://sandbox.runjs.cn/show/ignefell 效果2:http://runjs.cn/code/w2wxjy ...
- 7.数据处理函数 ---SQL
大多数SQL实现支持以下类型的函数. 用于处理文本字符串(如删除或填充值,转换值为大写或小写)的文本函数. 用于在数值数据上进行算术操作(如返回绝对值,进行代数运算)的数值函数. 用于处理日期和时间值 ...