在线浏览器网页版入口网站如何优化关键词排名
web/
2025/10/5 13:23:58/
文章来源:
在线浏览器网页版入口,网站如何优化关键词排名,wordpress mysql 挂了,wordpress导入demo数据库生命游戏其实是一个零玩家游戏#xff0c;它包括一个二维矩形世界#xff0c;这个世界中的每个方格居住着一个活着的或死了的细胞。一个细胞在下一个时刻生死取决于相邻八个方格中活着的或死了的细胞的数量。如果相邻方格活着的细胞数量过多#xff0c;这个细胞会因为资源匮…生命游戏其实是一个零玩家游戏它包括一个二维矩形世界这个世界中的每个方格居住着一个活着的或死了的细胞。一个细胞在下一个时刻生死取决于相邻八个方格中活着的或死了的细胞的数量。如果相邻方格活着的细胞数量过多这个细胞会因为资源匮乏而在下一个时刻死去相反如果周围活细胞过少这个细胞会因太孤单而死去。 具体规则如下
1如果一个细胞周围有3个细胞为生一个细胞周围共有8个细胞则该细胞为生即该细胞若原先为死则转为生若原先为生则保持不变 。 2 如果一个细胞周围有2个细胞为生则该细胞的生死状态保持不变 3 在其它情况下该细胞为死即该细胞若原先为生则转为死若原先为死则保持不变 在程序中使用0代表死1代表生。
串行模式
public class lifegame {public static ListString readTxt(String fileName){ListString listnew ArrayList();try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */File filename new File(fileName); // 要读取以上路径的input。txt文件InputStreamReader reader new InputStreamReader(new FileInputStream(filename)); // 建立一个输入流对象readerBufferedReader br new BufferedReader(reader); // 建立一个对象它把文件内容转成计算机能读懂的语言String line ;line br.readLine();while (line ! null) {list.add(line);line br.readLine();}} catch (Exception e) {e.printStackTrace();}return list;}public static void writeTxt(String content){try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */File writename new File(output.txt); // 相对路径如果没有则要建立一个新的output。txt文件writename.createNewFile(); // 创建新文件BufferedWriter out new BufferedWriter(new FileWriter(writename));out.write(content); // \r\n即为换行out.flush(); // 把缓存区内容压入文件out.close(); // 最后记得关闭文件} catch (Exception e) {e.printStackTrace();}}public boolean[][] world;public int len;int times;public lifegame(ListString list) {int nInteger.parseInt(list.get(0));worldnew boolean[n][n];this.lenn;this.timesInteger.parseInt(list.get(1));System.out.println(len);for(int i2;ilist.size();i){String[] templist.get(i).split(,);int xInteger.parseInt(temp[0]),yInteger.parseInt(temp[1]);world[x][y]true;}System.out.println(list.get(0)times);}public void print(){for(int i0;ilen;i){for(int j0;jlen;j)if(world[i][j])System.out.print(1);else System.out.print(0);System.out.println();}System.out.println();}private int[][] dirnew int[][]{{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{-1,1},{1,-1}};public void change(){int[][] countnew int[len][len];for(int i0;ilen;i)for(int j0;jlen;j)count[i][j]count(i,j);for(int i0;ilen;i)for(int j0;jlen;j)if(count[i][j]3){world[i][j]true;}else if(count[i][j]!2)world[i][j]false;}public int count(int x,int y){int ret0;for(int[] c:dir){int nextXc[0]x,nextYc[1]y;if(nextX0nextXlennextY0nextYlen){retworld[nextX][nextY]?1:0;}}return ret;}public static void main(String[] args){lifegame onnew lifegame(readTxt(input.txt));for(int i0;ion.times;i){on.change();}StringBuilder stringBuildernew StringBuilder();for(int i0;ion.len;i)for(int j0;jon.len;j){if(on.world[i][j]){stringBuilder.append(i).append(,).append(j).append(\r\n);}}writeTxt(stringBuilder.toString());}
}
并行模式
public class lifegame2 {public static ListString readTxt(String fileName){ListString listnew ArrayList();try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */File filename new File(fileName); // 要读取以上路径的input。txt文件InputStreamReader reader new InputStreamReader(new FileInputStream(filename)); // 建立一个输入流对象readerBufferedReader br new BufferedReader(reader); // 建立一个对象它把文件内容转成计算机能读懂的语言String line ;line br.readLine();while (line ! null) {list.add(line);line br.readLine();}} catch (Exception e) {e.printStackTrace();}return list;}public static void writeTxt(String content){try { // 防止文件建立或读取失败用catch捕捉错误并打印也可以throw/* 读入TXT文件 */File writename new File(output.txt); // 相对路径如果没有则要建立一个新的output。txt文件writename.createNewFile(); // 创建新文件BufferedWriter out new BufferedWriter(new FileWriter(writename));out.write(content); // \r\n即为换行out.flush(); // 把缓存区内容压入文件out.close(); // 最后记得关闭文件} catch (Exception e) {e.printStackTrace();}}int[][] count;private boolean[][] world;int len;public int times;public int getTimes() {return times;}public lifegame2(ListString list) {int nInteger.parseInt(list.get(0));worldnew boolean[n][n];countnew int[n][n];this.lenn;this.timesInteger.parseInt(list.get(1));System.out.println(len);for(int i2;ilist.size();i){String[] templist.get(i).split(,);int xInteger.parseInt(temp[0]),yInteger.parseInt(temp[1]);world[x][y]true;}System.out.println(list.get(0)times);}public void print(){for(int i0;ilen;i){for(int j0;jlen;j)if(world[i][j])System.out.print(1);else System.out.print(0);System.out.println();}System.out.println();}public String excute(int c){ExecutorService executorService Executors.newFixedThreadPool(c);for(int j0;jtimes;j){CountDownLatch countDownLatchnew CountDownLatch(c);Thread[] threads new Thread[10];for(int i0;ilen;ilen/c){excuteThread curnew excuteThread(count,i,ilen/c-1,world,countDownLatch);executorService.execute(cur);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}for(int i0;ilen;i)for(int k0;klen;k)if(count[i][k]3){world[i][k]true;}else if(count[i][k]!2)world[i][k]false;System.out.printf(第%d轮结束\n,j);}executorService.shutdown();while (!executorService.isTerminated()){}StringBuilder stringBuildernew StringBuilder();for(int i0;ilen;i)for(int j0;jlen;j){if(world[i][j]){stringBuilder.append(i).append(,).append(j).append(\r\n);}}return stringBuilder.toString();}public static void main(String[] args){lifegame2 onnew lifegame2(readTxt(input.txt));long sSystem.currentTimeMillis();String ton.excute(4);System.out.println(((double) (System.currentTimeMillis()-s))/1000);writeTxt(t);}
}
public class excuteThread implements Runnable{int[][] count;int l,r,len;boolean[][] world;CountDownLatch countDownLatch;public excuteThread(int [][] count,int l,int r,boolean[][] world,CountDownLatch countDownLatch) {lencount.length;this.countcount;this.ll;this.rr;this.countDownLatchcountDownLatch;this.worldworld;}Overridepublic void run() {System.out.println(线程l*4/len开始);for(int i0;ilen;i)for(int jl;jr;j)count[i][j]count(i,j);System.out.println(线程l*4/len结束);countDownLatch.countDown();}private int[][] dirnew int[][]{{0,1},{0,-1},{1,0},{-1,0},{1,1},{-1,-1},{-1,1},{1,-1}};public int count(int x,int y){int ret0;for(int[] c:dir){int nextXc[0]x,nextYc[1]y;if(nextX0nextXlennextY0nextYlen){retworld[nextX][nextY]?1:0;}}return ret;}
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/87389.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!