E - Polycarp and Snakes

题意:在一个全是点的图上开始画线,每次将一行或一列任意长度染成字母,一笔染一种字母,字母必须从a开始连续到后面某个字母可以覆盖。

问所给图案是否满足 ,若满足输出它画了几个字母,然后输出这每个字母开始和截止画的横纵坐标。

思路:存图,模拟,用个x1,x2,y1,y2记录每个字母出现位置的最小最大的横纵坐标,对于每个字母如果它的x1,x2,y1,y2不是初始值的话,那么它在图上就出现过(没有被覆盖掉),那么这个字母必然满足,x1==x2||y1==y2;

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. char mp[][];
  4. int x1[],x2[],y1[],y2[];
  5.  
  6. int main()
  7. {
  8. int n,m;
  9. int it=;
  10. scanf("%d",&it);
  11. while(it--)
  12. {
  13. scanf("%d%d",&n,&m);
  14. for(int i=; i<=n; i++)
  15. scanf("%s",mp[i]+);
  16. for(int i=; i<=; i++)
  17. {
  18. x1[i]=;
  19. y1[i]=;
  20. x2[i]=-;
  21. y2[i]=-;
  22. }
  23. for(int i=; i<=n; i++)
  24. for(int j=; j<=m; j++)
  25. {
  26. if(mp[i][j]!='.')
  27. {
  28. int num=mp[i][j]-'a'+;
  29. x1[num]=min(x1[num],i);
  30. x2[num]=max(x2[num],i);
  31. y1[num]=min(y1[num],j);
  32. y2[num]=max(y2[num],j);
  33. }
  34. }
  35. int flag=;
  36. int live[];
  37. int cnt=;
  38. memset(live,,sizeof(live));
  39. for(int i=; i<=; i++)
  40. {
  41. if(x1[i]!=&&y1[i]!=)
  42. {
  43. if(x1[i]==x2[i])
  44. {
  45. cnt=i;
  46. for(int j=y1[i]; j<=y2[i]; j++)
  47. if(mp[x1[i]][j]<('a'+i-))
  48. {
  49. flag=;
  50. break;
  51. }
  52. live[i]=;
  53. }
  54. else if(y1[i]==y2[i])
  55. {
  56. cnt=i;
  57. for(int j=x1[i]; j<=x2[i]; j++)
  58. {
  59. if(mp[j][y1[i]]<('a'+i-))
  60. {
  61. flag=;
  62. break;
  63. }
  64. }
  65. live[i]=;
  66. }
  67. else
  68. {
  69. flag=;
  70. break;
  71. }
  72. }
  73. }
  74. // for(int i=1; i<=5; i++)
  75. // printf("%d %d %d %d\n",x1[i],x2[i],y1[i],y2[i]);
  76. if(flag==)
  77. printf("NO\n");
  78. else
  79. {
  80. printf("YES\n%d\n",cnt);
  81. for(int i=; i<=cnt; i++)
  82. {
  83. if(live[i]==)
  84. {
  85. // printf("???");
  86. for(int j=i+; j<=; j++)
  87. {
  88. if(live[j]==)
  89. {
  90. printf("%d %d %d %d\n",x1[j],y1[j],x2[j],y2[j]);
  91. break;
  92. }
  93. }
  94. }
  95. else
  96. printf("%d %d %d %d\n",x1[i],y1[i],x2[i],y2[i]);
  97. }
  98. }
  99. }
  100. }

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. AI决策算法 之 GOAP (三)

    源码地址:http://pan.baidu.com/s/1dFwzmfB 这篇我们使用上篇文章写的GOAP框架来完成一个实例: 实例内容: AI有10HP, 需要去站岗,站岗完成扣5HP 当HP< ...

  2. android studio 改包名

    使用Android studio有一段时间了,但是每次修改包名的时候都是用一种简单粗暴的方式,那就是新建一个想要的包名,然后直接拖拽. 但是这样有个不好的地方就是每次都要去修改manifest.xml ...

  3. Noip2016day2 组合数问题problem

    题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...

  4. crm项目整理概要

    一.开发背景 由于公司人员的增多,原来通过excel表格存取方式过于繁琐,而且对于公司人员的调配和绩效考核等不能做到精确处理,所以开发crm系统,开始开发只是针对销售人员和客户,后面陆续加上一些操作, ...

  5. c#之quartz任务调度的使用

    这里讲下,quartz这种任务调度程序的简单使用 这是使用的quartz的3.x 版本 2.x 版本与此稍有区别,可以在网上查看2.x版本教程 使用语言为c# quartz的使用分为几个步骤 创建一个 ...

  6. Nacos深入浅出(三)

    EventDispatcher.fireEvent(new ConfigDataChangeEvent(true, dataId, group, tenant, time.getTime())); 跟 ...

  7. Delphi调用C# 编写dll动态库

    Delphi调用C# 编写dll动态库 编写C#dll的方法都一样,首先在vs2005中创建一个“类库”项目WZPayDll, using System.Runtime.InteropServices ...

  8. IDEA导入HttpServlet包

    转载此篇博客,言简意赅.https://blog.csdn.net/liu_yanzhao/article/details/78838670

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

  10. 51nod1244 莫比乌斯函数之和 杜教筛

    虽然都写了,过也过了,还是觉得杜教筛的复杂度好玄学 设f*g=h,∑f=S, 则∑h=∑f(i)S(n/i下取整) 把i=1时单独拿出来,得到 S(n)=(∑h-∑2->n f(i)S(n/i下 ...