第1次实验——NPC问题(回溯算法、聚类分析)

1、八皇后及N皇后问题

public class Queen {   
   private int[] column;  // 同栏是否有皇后,1表示有 
   private int[] rup;   // 右上至左下是否有皇后 
   private int[] lup;  // 左上至右下是否有皇后
   private int[] queen;   // 解答
   
 private int num; // 解答编号  
 private final int type = 8;  
 public Queen() {   
  column = new int[type+1];   
  rup = new int[2*type+1];   
  lup = new int[2*type+1];   
  for(int i = 1; i <= type; i++)   
   column[i] = 1;   
  for(int i = 1; i <= 2*type; i++)   
   rup[i] = lup[i] = 1;   
   queen = new int[type+1];  
  }   
 public void backtrack(int i) {   
  if(i > type) {   
   showAnswer();  
   } else {   
   for(int j = 1; j <= type; j++) {   
    if(column[j] == 1 && rup[i+j] == 1 && lup[i-j+type] == 1) {   
     queen[i] = j; // 设定为占用   
     column[j] = rup[i+j] = lup[i-j+type] = 0;   
     backtrack(i+1);   
     column[j] = rup[i+j] = lup[i-j+type] = 1;  
     }   
    }   
   }   
  }   
 protected void showAnswer() {   
  num++;   
  System.out.println("\n解答 " + num);   
  for(int y = 1; y <= type; y++) {   
   for(int x = 1; x <= type; x++) {   
    if(queen[y] == x) {   
     System.out.print(" Q");   
     } else {   
      System.out.print(" *");  
      }   
    }   
   System.out.println();   
   }   
  }   
 public static void main(String[] args) {   
  Queen q = new Queen();   
  q.backtrack(1);   
  }  
}


2、学生聚类分析思考

1、  项目实施方案

(1)     确定每种类型的学生在一天中的学习时间

(2)     通过调查问卷的形式,统计所有学生的情况,然后进行归类分析;

(3)      

2、 可以进行分类

3、 对于我来说,一天基本是这样安排的,白天是学习的时间,一般都是学习自己选定的方向的知识,下午是锻炼的时间,晚上可能看下电影,玩下游戏。目前的定向是网页开发这方面的,通过借阅图书,下载教学视频等方面来进行学习。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值