• abc322 d ( 枚举 + 几何 + 状态压缩


    1. #include
    2. using namespace std;
    3. const int f = (1<<16) - 1;
    4. void rotate(string s[]){
    5. char t[4][4];
    6. for(int i = 0 ; i < 4 ; i++){
    7. for(int j = 0 ; j < 4 ; j++){
    8. t[j][4-i-1] = s[i][j];
    9. }
    10. }
    11. for(int i = 0 ; i < 4 ; i++){
    12. s[i] = string(t[i] , t[i] + 4);//char数组转换为字符串
    13. }
    14. }
    15. bool check(int x){
    16. if(x > 3 || x < 0) return false;
    17. else return true;
    18. }
    19. int move(string s[] , int x , int y){
    20. int st = 0 ;
    21. for(int i = 0 ; i < 4 ; i++){
    22. for(int j = 0 ; j < 4 ; j++){
    23. if(s[i][j] == '#'){
    24. int xx = i + x;
    25. int yy = j + y;
    26. if(check(xx) && check(yy)){
    27. st |= 1<<(xx * 4 + yy);
    28. }else{
    29. return -1;
    30. }
    31. }
    32. }
    33. }
    34. return st;
    35. }
    36. vector<int> solve(){
    37. vector<int> ret;
    38. string s[4];
    39. for(int i = 0 ; i < 4 ; i++) cin>>s[i];
    40. for(int i = 0 ; i < 4 ; i++) {
    41. for (int x = -3; x <= 3; x++) {
    42. for (int y = -3; y <= 3; y++) {
    43. int v = move(s , x , y );
    44. if(v >= 0) ret.push_back(v);
    45. }
    46. }
    47. rotate(s);
    48. }
    49. return ret;
    50. }
    51. int main() {
    52. vector<int> r[3];
    53. for (int i = 0; i < 3; i++) {
    54. r[i] = solve();
    55. }
    56. for (auto x: r[0]) {
    57. for (auto y: r[1]){
    58. for (auto z: r[2]) {
    59. if(((x ^ y) ^ z) == f ){
    60. cout<<"Yes";
    61. return 0;
    62. }
    63. }
    64. }
    65. }
    66. cout<<"No";
    67. return 0;
    68. }

    属于是长知识了,关于枚举这个图形的摆放

    首先你得知道这个图形旋转的公式,

    然后枚举这个图形所有的移动情况,最多向左右上下移动3个,

    处理平移后的图形,将这个图形用二进制压缩一下,16个格子压缩成16位

    最后枚举三个图形的所有二进制情况  x ^ y  ^ z ==  f  

  • 相关阅读:
    LeetCode 0216.组合总和 III:回溯(剪枝) OR 二进制枚举
    kotlin构造方法
    NXP公司K60N512+PWM控制BLDC电机
    提升服务器性能相关
    华为三层交换机之基本操作
    15.RedHat认证-Ansible自动化运维(上)
    Leetcode 1124. 表现良好的最长时间段
    Flutter的oktoast插件详解
    flex 收缩计算、简写
    网站的常见攻击与防护方法
  • 原文地址:https://blog.csdn.net/m0_75125820/article/details/133470583