2017年浙江中医药大学大学生程序设计竞赛(重现赛)H - 剪纸

Posted Fighting Heart

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2017年浙江中医药大学大学生程序设计竞赛(重现赛)H - 剪纸相关的知识,希望对你有一定的参考价值。

题目描述

DD wants to send a gift to his best friend CC as her birthday is coming. However, he can’t afford expensive gifts, and he is so lazy that he is not willing to do complex things. So he decides to prepare a paper cut for CC’s birthday gift, which symbolizes their great friendship~~
DD has a square colored paper which consists of n*n small squares. Due to his tastes, he wants to cut the paper into two identical pieces. DD also wants to cut as many different figures as he can but each sheet can be only cut once, so he asks you how many sheets does he need to prepare at most.
for example:
技术分享图片技术分享图片

输入描述:

Input contains multiple test cases.
The first line contains an integer T (1<=T<=20), which is the number of test cases.Then the first line of each test case contains an integer n (1<=n<10).

输出描述:

The answer;
示例1

输入

1
4

输出

11

题解

暴力搜索。

因为是两个一模一样的图形,所以肯定中心对称,所以从中心出发,同时走两条相反方向的路即可。

#include <bits/stdc++.h>
using namespace std;

const int maxn = 15;
int T, n;
int f[maxn][maxn];
int ans;
int dir[4][2] = {
  {1, 0},
  {-1, 0},
  {0, 1},
  {0, -1},
};

bool check(int x, int y) {
  if(x == 0 || x == n || y ==0 || y == n) return 1;
  return 0;
}

bool out(int x, int y) {
  if(x >= 0 && x <= n && y >= 0 && y <= n) return 0;
  return 1;
}

void dfs(int x1, int y1, int x2, int y2) {
  if(check(x1, y1) && check(x2, y2)) {
    ans ++;
    return ;
  }
  for(int i = 0; i < 4; i ++) {
    int tx1 = x1 + dir[i][0];
    int ty1 = y1 + dir[i][1];
    int tx2 = x2 - dir[i][0] ;
    int ty2 = y2 - dir[i][1];
    if(f[tx1][ty1]) continue;
    if(f[tx2][ty2]) continue;
    if(out(tx1, ty1)) continue;
    if(out(tx2, ty2)) continue;
    f[tx1][ty1] = 1;
    f[tx2][ty2] = 1;
    dfs(tx1, ty1, tx2, ty2);
    f[tx1][ty1] = 0;
    f[tx2][ty2] = 0;
  }
}

int main() {
  scanf("%d", &T);
  while(T --) {
    scanf("%d", &n);

    if(n % 2 == 1) {
      printf("0\n");
      continue;
    }
    for(int i = 0; i <= n; i ++) {
      for(int j = 0; j <= n; j ++) {
        f[i][j] = 0;
      }
    }
    ans = 0;
    f[n / 2][n / 2] = 1;
    dfs(n / 2, n / 2, n / 2, n / 2);
    printf("%d\n", ans / 4);

  }
  return 0;
}

  

以上是关于2017年浙江中医药大学大学生程序设计竞赛(重现赛)H - 剪纸的主要内容,如果未能解决你的问题,请参考以下文章

2017年浙江中医药大学大学生程序设计竞赛(重现赛)A - 不存在的树

2019年湘潭大学程序设计竞赛(重现赛)

Permutation-水题-2017中国大学生程序设计竞赛-哈尔滨站-重现赛

2017中国大学生程序设计竞赛-总决赛-重现赛(感谢哈工大)

吉首大学2019年程序设计竞赛(重现赛)H 蛇皮走位

A Simple Stone Game-找素因子(欧拉函数)-2017中国大学生程序设计竞赛-哈尔滨站-重现赛