您的位置:首页 > 其它

蓝桥杯 第七届省赛试题 剪邮票

2016-04-15 17:27 239 查看
<div id="post_content_86165038147" class="d_post_content j_d_post_content  clearfix">            剪邮票

如【图1.jpg】, 有12张连在一起的12生肖的邮票。
现在你要从中剪下5张来,要求必须是连着的。
(仅仅连接一个角不算相连)
比如,【图2.jpg】,【图3.jpg】中,粉红色所示部分就是合格的剪取。

请你计算,一共有多少种不同的剪取方法。

请填写表示方案数目的整数。
注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。

<img style="cursor: url("http://tb2.bdstatic.com/tb/static-pb/img/cur_zin.cur"), pointer;" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=2e6a1bf805087bf47dec57e1c2d2575e/f7a2e8c451da81cb0a24a77e5566d0160b24318a.jpg" height="319" width="412" alt="" />
<img style="cursor: url("http://tb2.bdstatic.com/tb/static-pb/img/cur_zin.cur"), pointer;" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=26cc5ec927a446237ecaa56aa8237246/293cb7025aafa40f0015ea6eac64034f7af019f9.jpg" height="319" width="412" alt="" />
<img style="cursor: url("http://tb2.bdstatic.com/tb/static-pb/img/cur_zin.cur"), pointer;" class="BDE_Image" src="http://imgsrc.baidu.com/forum/w%3D580/sign=de82bcb75e82b2b7a79f39cc01accb0a/58c44ef40ad162d98d1546af16dfa9ec8813cdd2.jpg" height="319" width="412" alt="" /></div>

package com.diqijie.shengsai;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;

/**
* @author leibaobao 剪邮票
* 解: 深搜,效率不是很高,反正是填空题
*/
public class _7 {
public static int count = 0;
public static int [] a = new int[5];
public static HashSet<String> hashset = new HashSet<String>();
public static void main(String[] args) {
// TODO Auto-generated method stub
for(a[0] = 0; a[0] < 12; a[0]++)
for(a[1] = a[0]+1; a[1] < 12; a[1]++)
for(a[2] = a[1]+1; a[2] < 12; a[2]++)
for(a[3] = a[2]+1; a[3] < 12; a[3]++)
for(a[4] = a[3]+1; a[4] < 12; a[4]++)
if(jus()){
hashset.add(""+a[0]+a[1]+a[2]+a[3]+a[4]);
}
System.out.println(hashset.size());
}
private static boolean jus() {
// TODO Auto-generated method stub
boolean flag[] = new boolean[5];
dfs(flag,0);
return flag[0]&&flag[1]&&flag[2]&&flag[3]&&flag[4];
}

private static void dfs(boolean[] flag,int n) {
// TODO Auto-generated method stub
flag
= true;
for(int i = 0; i < 5; i++){
//加一减一要在同一行、加四减四要在同一列
if(!flag[i] && (a[i]/4 == a
/4) && (a[i] == a
- 1 || a[i] == a
+ 1)){
dfs(flag,i);
}
if (!flag[i] && (a[i]%4 == a
%4) && (a[i] == a
- 4 || a[i] == a
+ 4)){
dfs(flag,i);
}
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: