非常有毛病的一道题,我一个一个读字符死活过不去,改成整行整行读就 A 了...

做法就是...最小点覆盖...

我们发现可以把一个点向上跳看做被吃掉了,然后最顶层的点是无法向上跳所以不能被吃掉,然后被吃掉的点相连的边都会被删除...

这样转换完模型之后特判两下用二分图匹配就好了(因为这里的环最多是四元,或者说是偶数长度环...)

注意顶部的点必须要特判...因为顶部的点无法删除...

  1. //by Judge
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<iostream>
  5. #define Rg register
  6. #define fp(i,a,b) for(Rg int i=(a),I=(b)+1;i<I;++i)
  7. #define fd(i,a,b) for(Rg int i=(a),I=(b)-1;i>I;--i)
  8. #define go(u) for(Rg int i=head[u],v=e[i].to;i;v=e[i=e[i].nxt].to)
  9. using namespace std;
  10. const int N=103;
  11. const int M=2e4+3;
  12. typedef int MP[N][N];
  13. typedef int arr[M];
  14. #ifndef Judge
  15. #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
  16. #endif
  17. char buf[1<<21],*p1=buf,*p2=buf;
  18. inline int read(){ int x=0,f=1; char c=getchar();
  19. for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
  20. for(;isdigit(c);c=getchar()) x=x*10+c-'0'; return x*f;
  21. } inline int cread(int* s){ Rg int len=0; Rg char ch;
  22. while((ch=getchar())!='O'&&ch!='.');
  23. for(s[++len]=ch=='O';(ch=getchar())=='O'||ch=='.';s[++len]=ch=='O');
  24. return s[len+1]='\0',len;
  25. } char sr[1<<21],z[20];int C=-1,Z;
  26. inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
  27. inline void print(Rg int x,Rg char chr=' '){
  28. if(C>1<<20)Ot();if(x<0)sr[++C]=45,x=-x;
  29. while(z[++Z]=x%10+48,x/=10);
  30. while(sr[++C]=z[Z],--Z);sr[++C]=chr;
  31. } int n,cnt,tim,res,pat,head[M<<2];
  32. arr px,py,to,vis,bl,now,ok; MP id,mp;
  33. struct Edge{ int to,nxt; }e[M];
  34. inline void add(int u,int v){
  35. e[++pat]=(Edge){v,head[u]},head[u]=pat;
  36. }
  37. bool dfs(int u){ vis[u]=tim;
  38. go(u) if(vis[v]^tim){ vis[v]=tim;
  39. if(!to[v]||dfs(to[v])) return to[v]=u,1;
  40. } return 0;
  41. }
  42. int main(){
  43. fp(i,1,read()){ n=read(),cnt=pat=res=0;
  44. fp(i,1,n){
  45. cread(mp[i]);
  46. fp(j,1,n) if(mp[i][j])
  47. id[i][j]=++cnt,
  48. px[cnt]=i,py[cnt]=j,
  49. bl[cnt]=(i&1);
  50. }
  51. fp(i,1,n+1) mp[n+1][i]=0;
  52. memset(ok,0,(cnt+2)<<2);
  53. memset(to,0,(cnt+2)<<2);
  54. memset(vis,0,(cnt+2)<<2);
  55. memset(now,0,(cnt+2)<<2);
  56. memset(head,0,(cnt+2)<<2);
  57. fp(i,1,n) fp(j,1,n)
  58. if(mp[i][j]&&!mp[i-1][j-1]&&!mp[i-1][j+1]){
  59. now[id[i][j]]=1;
  60. if(mp[i+1][j+1]) now[id[i+1][j+1]]=2;
  61. if(mp[i+1][j-1]) now[id[i+1][j-1]]=2;
  62. }
  63. fp(i,1,cnt) res+=(now[i]==2);
  64. for(Rg int i=1;i<=n;i+=2) fp(j,1,n)
  65. if(mp[i][j]&&!now[id[i][j]]){
  66. if(mp[i-1][j-1]&&!now[id[i-1][j-1]])
  67. add(id[i][j],id[i-1][j-1]);
  68. if(mp[i-1][j+1]&&!now[id[i-1][j+1]])
  69. add(id[i][j],id[i-1][j+1]);
  70. if(mp[i+1][j-1]&&!now[id[i+1][j-1]])
  71. add(id[i][j],id[i+1][j-1]);
  72. if(mp[i+1][j+1]&&!now[id[i+1][j+1]])
  73. add(id[i][j],id[i+1][j+1]);
  74. }
  75. tim=0;
  76. fp(i,1,cnt) if(!now[i])
  77. if(++tim&&dfs(i)) ++res;
  78. fp(i,1,cnt) if(to[i]) ok[to[i]]=1;
  79. ++tim;
  80. fp(i,1,cnt) if(!now[i]&&bl[i]&&!ok[i]) dfs(i);
  81. fp(i,1,cnt) if(!now[i]&&bl[i]&&vis[i]^tim) now[i]=2;
  82. fp(i,1,cnt) if(!now[i]&&!bl[i]&&vis[i]==tim) now[i]=2;
  83. print(res,'\n');
  84. fd(i,cnt,1) if(now[i]&2){
  85. Rg int x=px[i],y=py[i]; print(x),print(y);
  86. sr[++C]=mp[x-1][y-1]?'L':'R',sr[++C]='\n';
  87. }
  88. } return Ot(),0;
  89. }
  90. /*
  91. 2
  92. 7
  93. OOOOOOO
  94. OOOOOOO
  95. OOOOOOO
  96. OOOOOOO
  97. OOOOOOO
  98. OOOOOOO
  99. OOOOOOO
  100. 3
  101. .O.
  102. O.O
  103. ...
  104. */

codechef: BINARY, Binary Movements的更多相关文章

  1. [线索二叉树] [LeetCode] 不需要栈或者别的辅助空间,完成二叉树的中序遍历。题:Recover Binary Search Tree,Binary Tree Inorder Traversal

    既上篇关于二叉搜索树的文章后,这篇文章介绍一种针对二叉树的新的中序遍历方式,它的特点是不需要递归或者使用栈,而是纯粹使用循环的方式,完成中序遍历. 线索二叉树介绍 首先我们引入“线索二叉树”的概念: ...

  2. # Leetcode 67:Add Binary(二进制求和)

    Leetcode 67:Add Binary(二进制求和) (python.java) Given two binary strings, return their sum (also a binar ...

  3. leetcode105:Construct Binary Tree from Preorder and Inorder Traversal

    题目: Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume t ...

  4. leetcode:Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  5. leetcode:Invert Binary Tree

    Invert a binary tree. 4 / \ 2 7 / \ / \ 1 3 6 9 to 4 / \ 7 2 / \ / \ 9 6 3 1即反转二叉树,代码如下: /** * Defin ...

  6. lintcode :Invert Binary Tree 翻转二叉树

    题目: 翻转二叉树 翻转一棵二叉树 样例 1 1 / \ / \ 2 3 => 3 2 / \ 4 4 挑战 递归固然可行,能否写个非递归的? 解题: 递归比较简单,非递归待补充 Java程序: ...

  7. [LeetCode]题解(python):106-Construct Binary Tree from Inorder and Postorder Traversal

    题目来源: https://leetcode.com/problems/construct-binary-tree-from-inorder-and-postorder-traversal/ 题意分析 ...

  8. [LeetCode]题解(python):105-Construct Binary Tree from Preorder and Inorder Traversal

    题目来源: https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/ 题意分析: ...

  9. [LeetCode]题解(python):099-Recover Binary Search Tree

    题目来源: https://leetcode.com/problems/recover-binary-search-tree/ 题意分析: 二叉搜索树中有两个点错了位置,恢复这棵树. 题目思路: 如果 ...

随机推荐

  1. SPOJ ARCTAN

    POJ1183 除输入方式外与这道题完全一样 题目大意是给定一个a 求最小的满足arctan(1/A)=arctan(1/B)+arctan(1/C) 的B+C的最小值 根据上述递推规律,我们只要从2 ...

  2. [luoguP2672] 推销员(贪心 + 树状数组 + 优先队列)

    传送门 贪心...蒟蒻证明不会... 每一次找最大的即可,找出一次最大的,数列会分为左右两边,左边用stl优先队列维护,右边用树状数组维护.. (线段树超时了....) 代码 #include < ...

  3. [luoguP1058] 立体图(超级大模拟(¬︿̫̿¬☆))

    传送门 看到题后整个人成了mengbier 但是仔细分析一下就很简单了,先确定好输出的图的长和宽. 然后从输入的矩形的左上角的最下面的开始填充,顺序是从下到上,从左到右,从后往前. 填充的时候直接覆盖 ...

  4. 【spring boot 系列】spring data jpa 全面解析(实践 + 源码分析)

    前言 本文将从示例.原理.应用3个方面介绍spring data jpa. 以下分析基于spring boot 2.0 + spring 5.0.4版本源码 概述 JPA是什么? JPA (Java ...

  5. hash存储结构【六】

    一.概述: 我们可以将Redis中的Hashes类型看成具有String Key和String Value的map容器.所以该类型非常适合于存储值对象的信息.如Username.Password和Ag ...

  6. NOIP 2010 关押罪犯

    P1525 关押罪犯 题目描述 SS 城现有两座监狱,一共关押着 NN 名罪犯,编号分别为 1-N1−N .他们之间的关系自然也极不和谐.很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突. ...

  7. Linux学习系列之lvs+keepalived

    LVS简介 LVS介绍 LVS是Linux Virtual Server的缩写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统,属于4层负载均衡 ipvs和ipvsadm的关系 我们使用配置LV ...

  8. 018 cisco 3560 MAC地址绑定

    在3560交换机上show ip dhcp binding 可以看到通过DHCP服务广播出去的IP地址与MAC地址的对应表: 比如: Switch#show ip dhcp binding IP ad ...

  9. C#.NET 如何快速输入一个对象事件对应的方法

    直接在Textbox图像对象中找到这个对象的KeyPress方法,然后输入触发的事件名称.效率更高,不容易出错. "void TypeAreaKeyPress(object sender, ...

  10. vue之父子组件之间的通信方式

    (一)props与$emit <!-这部分是一个关于父子组件之间参数传递的例子--> <!--父组件传递参数到子组件是props,子组件传递参数到父组件是用事件触发$emit--&g ...