蓝桥杯 第七届省赛试题 方格填数
2016-04-08 21:01
197 查看
package com.diqijie.shengsai; /** * @author leibaobao *方格填数 *解:没想太多,全排列能做的,加几个判断就好。想多了浪费时间 */ public class _6 { public static int count = 0; public static void swap(char array[], int a, int b) { char temp = array[a]; array[a] = array[b]; array[b] = temp; } public static void Permutation(char[] str, int a, int length) { if (a == length) { if (jud(str)) { count++; System.out.println(String.valueOf(str)); } } else { for (int i = a; i <= length; i++) { swap(str, i, a); Permutation(str, a + 1, length); swap(str, i, a); } } } private static boolean jud(char [] str) { if(jus1(str[0], str[1]) && jus1(str[0], str[3]) && jus1(str[0], str[4]) && jus1(str[0], str[5]) && jus1(str[1], str[2]) && jus1(str[1], str[4]) && jus1(str[1], str[5]) && jus1(str[1], str[6]) && jus1(str[2], str[5]) && jus1(str[2], str[6]) && jus1(str[3], str[4]) && jus1(str[3], str[7]) && jus1(str[3], str[8]) && jus1(str[4], str[5]) && jus1(str[4], str[7]) && jus1(str[4], str[8]) && jus1(str[4], str[9]) && jus1(str[5], str[6]) && jus1(str[5], str[8]) && jus1(str[5], str[9]) && jus1(str[6], str[9]) && jus1(str[7], str[8]) && jus1(str[8], str[9])) return true; return false; } private static boolean jus1(char c, char d) { // TODO Auto-generated method stub if(c == (d+1) || c == (d-1)) return false; return true; } public static void main(String[] args) { char[] str = "0123456789".toCharArray(); Permutation(str, 0, 9); System.out.println(count); } }
相关文章推荐
- PHP单文件上传的过程化函数封装
- HDOJ 5646-DZY Loves Partition【数学】
- poj 3050 hopscotch
- HDU 1257 最少拦截系统
- c++ 友元类
- vi 编辑器
- python数据类型
- 细说dex2oat(3)
- android studio 2.0Stable (正式版下载)
- 对字符串进行简单的字符数字统计 探索java中的List功能
- 分支界限法
- nyoj 119 士兵杀敌(三)(RMQ)
- iOS 登录
- C语言中取余与取模的区别
- poj 2762 Going from u to v or from v to u? trajan+拓扑
- Timus 2070 Interesting Numbers
- 坐在马桶上看只有五行的floyd算法
- 最牛最暴力的开源协议:WTFPL
- 用MFC “菜单响应事件” 实现绘图
- [JZOJ4296]有趣的有趣的家庭菜园