第1次实验——NPC问题(回溯算法、聚类分析)
2014-06-12 00:46
302 查看
public class Queen { int size; int resultCount; int flag=0; public void compute ( int size ) { this.size = size; resultCount = 0; int data[] = new int[size]; int count; // 所有可能的情况个数 int i,j; // 计算所有可能的情况的个数 count = 1; for ( i=0 ; i<size ; i++ ) { count = count * size; } // 对每一个可能的情况 for ( i=0 ; i<count ; i++ ) { // 计算这种情况下的棋盘上皇后的摆放位置,用 8 进制数表示 // 此处可优化 int temp = i; for ( j=0 ; j<size ; j++ ) { data [j] = temp % size; temp = temp / size; } // 测试这种情况是否可行,如果可以,输出 if ( test(data)&&flag<3){ output( data ); flag++;} } } /* * 测试这种情况皇后的排列是否可行 * */ public boolean test( int[] data ) { int i,j; for ( i=0 ; i<size ; i++ ) { for ( j=i+1 ; j<size ; j++ ) { // 测试是否在同一排 if ( data[i] == data[j] ) return false; // 测试是否在一斜线 if ( (data[i]+i) == (data[j]+j) ) return false; // 测试是否在一反斜线 if ( (data[i]-i) == (data[j]-j) ) return false; } } return true; } /* * 输出某种情况下皇后的坐标 * */ public void output ( int[] data ) { int i; System.out.print ( ++resultCount + ": " ); for ( i=0 ; i<size ; i++ ) { System.out.print ( "(" + i + "," + data[i] + ") " ); } System.out.println (); } public static void main(String args[]) { (new Queen()).compute( 8 ); } }
、
学生聚类分析思考
对学生进行分组,并将k个学生分别分配给中心向量C1、C2、C3、....、Ck,
其中 学生会别分成,学霸型,自我中心型,游戏人生型,游戏与学习型这四种,
然后对所有学生进行调查,例如学习时间的长度,以及去图书馆的次数,电脑游戏时间,
娱乐时间,再对各项数据的归并统计,可以得到学生的类型
我会对学生进行分类,要素有很多
相关文章推荐
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析) N皇后的问题
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验 - NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验--NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)
- 第1次实验——NPC问题(回溯算法、聚类分析)