六角幻方
来源:互联网 发布:开源房产cms 编辑:程序博客网 时间:2024/05/16 01:19
/* * 标题:六角幻方 把 1 2 3 ... 19 共19个整数排列成六角形状,如下: * * * * * * * * * * * * * * * * * * * 要求每个直线上的数字之和必须相等。共有15条直线哦! 再给点线索吧!我们预先填好了2个数字,第一行的头两个数字是:15 13,参见图【p1.png】,黄色一行为所求。 请你填写出中间一行的5个数字。数字间用空格分开。 这是一行用空格分开的整数,请通过浏览器提交答案,不要填写任何多余的内容(比如说明性的文字等) */public class Main{ public static void main(String[] args) { int[] a={1,2,3,4,5,6,7,8,9,11,12,14,16,17,18,19}; f(a,0); System.out.println("finish!"); } public static void f(int[] x,int k){ if(k>=x.length){ test(x); return; } for(int i=k;i<x.length;i++){ {int t=x[k];x[k]=x[i];x[i]=t;} if(k==3){ if(x[0]+x[1]+x[2]+x[3]!=38){ {int t=x[i];x[i]=x[k];x[k]=t;} continue; } } if(k==8){ if(x[4]+x[5]+x[6]+x[7]+x[8]!=38){ {int t=x[i];x[i]=x[k];x[k]=t;} continue; } } if(k==12){ if(x[9]+x[10]+x[11]+x[12]!=38){ {int t=x[i];x[i]=x[k];x[k]=t;} continue; } } if(k==15){ if(x[13]+x[14]+x[15]!=38){ {int t=x[i];x[i]=x[k];x[k]=t;} continue; } } f(x,k+1); {int t=x[i];x[i]=x[k];x[k]=t;} } } public static void test(int[] x){ int s1=15+x[0]+x[4]; int s2=13+x[1]+x[5]+x[9]; int s3=10+x[2]+x[6]+x[10]+x[13]; int s4=x[3]+x[7]+x[11]+x[14]; int s5=x[8]+x[12]+x[15]; int s6=10+x[3]+x[8]; int s7=13+x[2]+x[7]+x[12]; int s8=15+x[1]+x[6]+x[11]+x[15]; if(s1==38&&s2==38&&s3==38&&s4==38&&s5==38&&s6==38&&s7==38&&s8==38){ System.out.print("#########"); for(int i=0;i<x.length;i++){ System.out.print(x[i]+" "); } System.out.println(); }// for(int i=0;i<x.length;i++){// System.out.print(x[i]+" ");// }// System.out.println(); }}
阅读全文
0 0
- 六角幻方
- 六角幻方
- 蓝桥杯 六角幻方
- 六角幻方(DFS)
- 六角幻方
- 六角幻方
- 六角幻方—题解
- 六角幻方 蓝桥试题
- 六角幻方(dfs+剪枝)
- 蓝桥杯 六角幻方 2014年JavaB组决赛试题
- (接上)第10题六角幻方
- 蓝桥杯java第五届决赛第二题--六角幻方
- 第五届蓝桥杯软件类国赛真题-C-A-2_六角幻方
- 六角幻方--详解第五届蓝桥杯大赛Java本科B组决赛真题
- 六角架构
- 六角图 设计
- Java 打印六角星
- 愿意u六角恐龙
- 二层交换和三层交换
- Java线程安全总结(二)
- MINA2.0 原理
- UItextField占位符在中间
- 到底什么才是闭包
- 六角幻方
- 个人笔记 org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.
- Java入门基础之【对象和类】3
- Hibernate——配置文件中数据类型date与timestamp区别
- HDU 1242 Rescue
- 用R语言的MICE包对缺失数据进行多重插补(一)-- 缺失数据分析
- C++对象模型
- gym 101170 NWERC 2016 I Iron and Coal
- linux系统安装git,nodejs,mysql