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 ...
随机推荐
- AI决策算法 之 GOAP (三)
源码地址:http://pan.baidu.com/s/1dFwzmfB 这篇我们使用上篇文章写的GOAP框架来完成一个实例: 实例内容: AI有10HP, 需要去站岗,站岗完成扣5HP 当HP< ...
- android studio 改包名
使用Android studio有一段时间了,但是每次修改包名的时候都是用一种简单粗暴的方式,那就是新建一个想要的包名,然后直接拖拽. 但是这样有个不好的地方就是每次都要去修改manifest.xml ...
- Noip2016day2 组合数问题problem
题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...
- crm项目整理概要
一.开发背景 由于公司人员的增多,原来通过excel表格存取方式过于繁琐,而且对于公司人员的调配和绩效考核等不能做到精确处理,所以开发crm系统,开始开发只是针对销售人员和客户,后面陆续加上一些操作, ...
- c#之quartz任务调度的使用
这里讲下,quartz这种任务调度程序的简单使用 这是使用的quartz的3.x 版本 2.x 版本与此稍有区别,可以在网上查看2.x版本教程 使用语言为c# quartz的使用分为几个步骤 创建一个 ...
- Nacos深入浅出(三)
EventDispatcher.fireEvent(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime())); 跟 ...
- Delphi调用C# 编写dll动态库
Delphi调用C# 编写dll动态库 编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll, using System.Runtime.InteropServices ...
- IDEA导入HttpServlet包
转载此篇博客,言简意赅.https://blog.csdn.net/liu_yanzhao/article/details/78838670
- CodeForces - 508B-Anton and currency you all know
Berland, 2016. The exchange rate of currency you all know against the burle has increased so much th ...
- 51nod1244 莫比乌斯函数之和 杜教筛
虽然都写了,过也过了,还是觉得杜教筛的复杂度好玄学 设f*g=h,∑f=S, 则∑h=∑f(i)S(n/i下取整) 把i=1时单独拿出来,得到 S(n)=(∑h-∑2->n f(i)S(n/i下 ...