-
Notifications
You must be signed in to change notification settings - Fork 7
/
Program.cs
56 lines (55 loc) · 1.67 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
namespace ReconstructA2RowBinaryMatrix
{
class Program
{
static void Main(string[] args)
{
int upper = 9;
int lower = 2;
int[] colsum = { 0, 1, 2, 0, 0, 0, 0, 0, 2, 1, 2, 1, 2 };
Console.WriteLine(ReconstructMatrix(upper, lower, colsum));
}
static IList<IList<int>> ReconstructMatrix(int upper, int lower, int[] colsum)
{
var res = new int[2][];
res[0] = new int[colsum.Length];
res[1] = new int[colsum.Length];
for (int i = 0; i < colsum.Length; i++)
{
if( colsum[i] == 2)
{
res[0][i] = 1;
res[1][i] = 1;
upper--;
lower--;
}
if(upper < 0 || lower < 0)
return new List<IList<int>>();
}
for (int i = 0; i < colsum.Length; i++)
{
if (colsum[i] == 1)
{
if (upper != 0)
{
res[0][i] = 1;
upper--;
}
else
{
res[1][i] = 1;
lower--;
}
if (upper < 0 || lower < 0)
return new List<IList<int>>();
}
}
if (upper != 0 || lower != 0)
return new List<IList<int>>();
return res;
}
}
}