public class Solution
{
public int MatrixScore(int[][] A)
{
var row = A.GetLength();
var col = A[].GetLength();
//判断最高位是否为1
for (int i = ; i < row; i++)
{
if (!(A[i][] == ))//不是1,则移动此行
{
for (int j = ; j < col; j++)
{
if (A[i][j] == )
{
A[i][j] = ;
}
else
{
A[i][j] = ;
}
}
}
} //遍历每一列,计算0和1的数量,如果0多,则移动
for (int j = ; j < col; j++)
{
var sum0 = ;
var sum1 = ;
for (int i = ; i < row; i++)
{
if (A[i][j] == )
{
sum0++;
}
else
{
sum1++;
}
}
if (sum0 > sum1)
{
for (int i = ; i < row; i++)
{
if (A[i][j] == )
{
A[i][j] = ;
}
else
{
A[i][j] = ;
}
}
}
} //计算最后的二进制数
var sum = ;
for (int i = ; i < row; i++)
{
var rowsum = ;
for (int j = col - ; j >= ; j--)
{
var cur = A[i][j] * (int)Math.Pow(, col - - j);
rowsum += cur;
}
sum += rowsum;
} return sum;
}
}

leetcode861的更多相关文章

  1. [Swift]LeetCode861. 翻转矩阵后的得分 | Score After Flipping Matrix

    We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...

随机推荐

  1. HTML DOM知识点补充:

    DOM Console 控制台对象提供了浏览器的debug的方法支持. 常用的:console.log(). ⚠️coffeescript中,这个方法不加括号. DOM Document 当一个HTM ...

  2. IAR使用notice

    1.IAR中无法程序跳转问题 在工程的C编译器选项里的预编译添加$TOOLKIT_DIR$\inc解决,需要clean一下工程再make即可.($TOOLKIT_DIR$:这个语法表示包含文件的路径在 ...

  3. poj3680

    题解: 相邻的建边 每一段建边 然后见一个原点,汇点 代码: #include<cstdio> #include<cmath> #include<cstring> ...

  4. JavaScript基本概要

    body, table{font-family: 微软雅黑; font-size: 10pt} table{border-collapse: collapse; border: solid gray; ...

  5. 作业要求20181023-4 Alpha阶段第2周/共2周 Scrum立会报告+燃尽图 01

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2284] 版本控制:https://git.coding.net/liuyy08 ...

  6. specialized English for automation-Lesson 2 Basic Circuits of Operational Amplifiers

    排版有点乱.... ========================================================================= Operational Ampl ...

  7. 接口测试SoapUI参数化之Datasource20151002

    上次和大家一起完成了soapui的参数之一properties,今天我们一起交流另外一种参数化的方法,跟着一起练习,不懂不要紧,练习多了就会慢慢懂的: 1.准备excle(目前soapui只支持xls ...

  8. ACdream区域赛指导赛之手速赛系列(2)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/DaiHaoC83E15/article/details/26187183        回到作案现场 ...

  9. aop学习

    拦截器和过滤器的区别:https://blog.csdn.net/heyeqingquan/article/details/71482169 1,aop是一个编程思想,不是具体的实现,一般有Filte ...

  10. bzoj2431逆序对数列

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2431 很容易想到n^3的做法.就是前 i 个数用第 i 个数最多能 i - 1 个逆序对,所 ...