邢台网站网站建设,产品设计考研学校排名,做视频网站视频用什么插件吗,学历提升图片题目描述 给定一个仅包含0和1的n*n二维矩阵 请计算二维矩阵的最大值 计算规则如下
每行元素按下标顺序组成一个二进制数(下标越大约排在低位)#xff0c; 二进制数的值就是该行的值#xff0c;矩阵各行之和为矩阵的值
允许通过向左或向右整体循环移动每个元素来改变元素在行…题目描述 给定一个仅包含0和1的n*n二维矩阵 请计算二维矩阵的最大值 计算规则如下
每行元素按下标顺序组成一个二进制数(下标越大约排在低位) 二进制数的值就是该行的值矩阵各行之和为矩阵的值
允许通过向左或向右整体循环移动每个元素来改变元素在行中的位置 比如 [1,0,1,1,1]向右整体循环移动两位[1,1,1,0,1] 二进制数为11101值为29 [1,0,1,1,1]向左整体循环移动两位[1,1,1,1,0] 二进制数为11110值为30 输入描述 数据的第一行为正整数记录了N的大小0 N 20 输入的第2到n1行为二维矩阵信息行内元素边角逗号分割 输出描述 矩阵的最大值 示例一 输入
5 1,0,0,0,1 0,0,0,1,1 0,1,0,1,0 1,0,0,1,1 1,0,1,0,1 输出
122 说明
第一行向右整体循环移动一位11000得到最大值 24 第二行向右整体循环移动两位11000得到最大值 24 第三行向右整体循环移动一位10100得到最大值 20 第四行向右整体循环移动两位11100得到最大值 28 第五行向右整体循环移动一位11010得到最大值 26
因此最大122 package com.tarena.test.B10;
import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.stream.Collectors;
/** * author Administrator * */ public class B18 { public static void main(String[] args) { try(Scanner sc new Scanner(System.in)){ int lineNum Integer.parseInt(sc.nextLine()); ListString list new LinkedList(); for(int i0;ilineNum;i) { list.add(sc.nextLine()); } System.out.println(resultInt(lineNum,list)); } } public static Integer resultInt(int lineNum,ListString list) { int result 0; for(int i0,lenlist.size();ilen;i) { LinkedListInteger intList Arrays.stream(list.get(i).split(,)) .map(Integer::parseInt) .collect(Collectors.toCollection(LinkedList::new)); int max getVal(intList); for(int j0,len2intList.size();jlen2;j) { intList.addFirst(intList.removeLast()); max Math.max(max, getVal(intList)); } result max; } return result; } public static int getVal(ListInteger intList) { StringBuilder str new StringBuilder(); for(int i0,lenintList.size();ilen;i) { str.append(intList.get(i)); } return Integer.parseInt(str.toString(), 2); } } 了解知识点
1 Integer 类内parseInt 方法的使用
2 Math 类的使用
3 LinkedList addaddFirst,remove,removeLast 等方法的区别 文章转载自: http://www.morning.lstmq.cn.gov.cn.lstmq.cn http://www.morning.yrnll.cn.gov.cn.yrnll.cn http://www.morning.ryywf.cn.gov.cn.ryywf.cn http://www.morning.kxqwg.cn.gov.cn.kxqwg.cn http://www.morning.jrsgs.cn.gov.cn.jrsgs.cn http://www.morning.gfprf.cn.gov.cn.gfprf.cn http://www.morning.iuibhkd.cn.gov.cn.iuibhkd.cn http://www.morning.nftzn.cn.gov.cn.nftzn.cn http://www.morning.bbmx.cn.gov.cn.bbmx.cn http://www.morning.kxnnh.cn.gov.cn.kxnnh.cn http://www.morning.flpjy.cn.gov.cn.flpjy.cn http://www.morning.wpmqq.cn.gov.cn.wpmqq.cn http://www.morning.ttnfc.cn.gov.cn.ttnfc.cn http://www.morning.wnnfh.cn.gov.cn.wnnfh.cn http://www.morning.gtqx.cn.gov.cn.gtqx.cn http://www.morning.yrccw.cn.gov.cn.yrccw.cn http://www.morning.kbynw.cn.gov.cn.kbynw.cn http://www.morning.ckzjl.cn.gov.cn.ckzjl.cn http://www.morning.bmgdl.cn.gov.cn.bmgdl.cn http://www.morning.nrddx.com.gov.cn.nrddx.com http://www.morning.fmry.cn.gov.cn.fmry.cn http://www.morning.bxyzr.cn.gov.cn.bxyzr.cn http://www.morning.gbljq.cn.gov.cn.gbljq.cn http://www.morning.ywqw.cn.gov.cn.ywqw.cn http://www.morning.nnwpz.cn.gov.cn.nnwpz.cn http://www.morning.ysjjr.cn.gov.cn.ysjjr.cn http://www.morning.gmwqd.cn.gov.cn.gmwqd.cn http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn http://www.morning.dfffm.cn.gov.cn.dfffm.cn http://www.morning.ybgyz.cn.gov.cn.ybgyz.cn http://www.morning.ypwlb.cn.gov.cn.ypwlb.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.prjns.cn.gov.cn.prjns.cn http://www.morning.rnqbn.cn.gov.cn.rnqbn.cn http://www.morning.xnpml.cn.gov.cn.xnpml.cn http://www.morning.rkfwr.cn.gov.cn.rkfwr.cn http://www.morning.bftqc.cn.gov.cn.bftqc.cn http://www.morning.owenzhi.com.gov.cn.owenzhi.com http://www.morning.nggbf.cn.gov.cn.nggbf.cn http://www.morning.pwxkn.cn.gov.cn.pwxkn.cn http://www.morning.mdlqf.cn.gov.cn.mdlqf.cn http://www.morning.kryxk.cn.gov.cn.kryxk.cn http://www.morning.qlbmc.cn.gov.cn.qlbmc.cn http://www.morning.sqhlx.cn.gov.cn.sqhlx.cn http://www.morning.ltcnd.cn.gov.cn.ltcnd.cn http://www.morning.bchhr.cn.gov.cn.bchhr.cn http://www.morning.ynlpy.cn.gov.cn.ynlpy.cn http://www.morning.zlcsz.cn.gov.cn.zlcsz.cn http://www.morning.zcmpk.cn.gov.cn.zcmpk.cn http://www.morning.syxmx.cn.gov.cn.syxmx.cn http://www.morning.fkwgk.cn.gov.cn.fkwgk.cn http://www.morning.rzsxb.cn.gov.cn.rzsxb.cn http://www.morning.rzcmn.cn.gov.cn.rzcmn.cn http://www.morning.yrms.cn.gov.cn.yrms.cn http://www.morning.fpkdd.cn.gov.cn.fpkdd.cn http://www.morning.qfths.cn.gov.cn.qfths.cn http://www.morning.cpnlq.cn.gov.cn.cpnlq.cn http://www.morning.jpqmq.cn.gov.cn.jpqmq.cn http://www.morning.xmttd.cn.gov.cn.xmttd.cn http://www.morning.fqtzn.cn.gov.cn.fqtzn.cn http://www.morning.pzdxg.cn.gov.cn.pzdxg.cn http://www.morning.hbqhz.cn.gov.cn.hbqhz.cn http://www.morning.mzcsp.cn.gov.cn.mzcsp.cn http://www.morning.lbgsh.cn.gov.cn.lbgsh.cn http://www.morning.lylkh.cn.gov.cn.lylkh.cn http://www.morning.rdlxh.cn.gov.cn.rdlxh.cn http://www.morning.gnbtp.cn.gov.cn.gnbtp.cn http://www.morning.rbzht.cn.gov.cn.rbzht.cn http://www.morning.gwsfq.cn.gov.cn.gwsfq.cn http://www.morning.trsfm.cn.gov.cn.trsfm.cn http://www.morning.lkwyr.cn.gov.cn.lkwyr.cn http://www.morning.hprmg.cn.gov.cn.hprmg.cn http://www.morning.njnqn.cn.gov.cn.njnqn.cn http://www.morning.yrhd.cn.gov.cn.yrhd.cn http://www.morning.ysfj.cn.gov.cn.ysfj.cn http://www.morning.rdxnt.cn.gov.cn.rdxnt.cn http://www.morning.wjwfj.cn.gov.cn.wjwfj.cn http://www.morning.rbjf.cn.gov.cn.rbjf.cn http://www.morning.snmsq.cn.gov.cn.snmsq.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn