2017年浙江中医药大学大学生程序设计竞赛

来源:互联网 发布:樊登读书会mac版 编辑:程序博客网 时间:2024/04/28 05:36

题目描述

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

输入

14

输出

11

point:

从中心开始DFS。


#include <set>#include <map>#include <math.h>#include <vector>#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>using namespace std;#define  LL long longconst LL maxn = 55;int dir[4][2]={0,1,0,-1,1,0,-1,0};int n;int ans;int flag[maxn][maxn];int check(int x,int y){if(x==1||x==n+1||y==1||y==n+1) return 1;return 0;}int out(int x,int y){if(x >= 1 && x <= n+1 && y >= 1 && y <= n+1) 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 xx1=x1+dir[i][0];int yy1=y1+dir[i][1];int xx2=x2-dir[i][0];int yy2=y2-dir[i][1];if(flag[xx1][yy1]||flag[xx2][yy2]) continue;if(out(xx1,yy1)||out(xx2,yy2)) continue;flag[xx1][yy1]=1;flag[xx2][yy2]=1;dfs(xx1,yy1,xx2,yy2);flag[xx1][yy1]=0;flag[xx2][yy2]=0;}}int main(){int T;scanf("%d",&T);while(T--){ans = 0;scanf("%d",&n);memset(flag,0,sizeof flag);if(n&1){printf("0\n");}else{flag[n/2+1][n/2+1]=1;dfs(n/2+1,n/2+1,n/2+1,n/2+1);printf("%d\n",ans/4);}}}


阅读全文
'); })();
0 0
原创粉丝点击
热门IT博客
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 哪里有卖高加索幼犬 如何训练萨摩耶幼犬 幼狮500 幼狮250 贝纳利幼狮250 贝纳利幼狮500 幼狮500价格 幼狮800 幼狮书盟 呆子幼狮250缺点 贝纳利幼狮250详细参数 贝纳利幼狮250价格 幼猫吃什么 幼猫猫粮 幼猫怎么养 如何训练幼猫晚上不叫 小新与幼猫 幼猫拉稀 幼猫疫苗 幼猫洗澡 怎么判断幼猫要死 幼猫食量对照表 被幼猫抓伤出血要打针吗 幼猫什么时候打疫苗 幼猫带回家三天几乎没吃饭 幼猫驱虫 幼猫拉肚子 幼猫感冒 幼猫不吃东西怎么办 幼猫拉稀怎么办 被幼猫抓伤轻微出血 幼猫喉咙一直咕噜咕噜原因 幼猫为什么死活不吃猫粮 被幼猫咬出血 幼猫可以吃火腿肠吗 幼猫一天喂几次 幼猫打喷嚏 幼猫可以吃什么 2至6月幼猫喂养方法 幼猫软便会自愈吗 幼猫流鼻涕感冒会自愈吗