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

来源:互联网 发布:linux新建 删除文件夹 编辑:程序博客网 时间:2024/05/16 11:06

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


0 0