-
Notifications
You must be signed in to change notification settings - Fork 0
/
Algo.cs
132 lines (112 loc) · 2.84 KB
/
Algo.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
namespace MyApp;
public class Algo
{
/**
Problem: A.Checkered board
Compiler: C# (MS .Net 6.0)+ASP
Verdict: OK
Status: Full solution
*/
static void A(string[] args)
{
/*
var n = int.Parse(args[0]);
var k = int.Parse(args[1]);
*/
var input = File
.ReadAllLines("input.txt")[0]
.Split(' ');
var n = int.Parse(input[0]);
var k = int.Parse(input[1]);
if ((k == 1 && n > 1) || ((n * n) % k != 0))
{
Console.WriteLine("No");
return;
}
var pool = new int[k];
Array.Fill(pool, (n * n) / k);
var result = new int[n][];
var color = 0;
for (var i = 0; i < n; i++)
{
result[i] = new int[n];
for (var j = 0; j < n; j++)
{
var tries = -1;
while (tries <= k)
{
tries++;
color++;
if (color > k)
{
color = 1;
}
if ((i == 0 || result[i - 1][j] != color) && (j == 0 || result[i][j - 1] != color) &&
pool[color - 1] > 0)
{
break;
}
}
if (tries > k)
{
Console.WriteLine("No");
return;
}
pool[color - 1]--;
result[i][j] = color;
}
}
Console.WriteLine("Yes");
foreach (var row in result)
{
foreach (var elm in row)
{
Console.Write(elm);
Console.Write(' ');
}
Console.WriteLine();
}
}
// unfinished
static void B(string[] args)
{
var input = File.ReadAllLines("input.txt");
var nums = new int[]
{
0,
5, // 2
4, // 3
3, // 4
2, // 5
2, // 6
2, // 7
2, // 8
2, // 9
};
var t = int.Parse(input[0]);
for (var i = 1; i < t; i++)
{
var line = input[i].Split(' ');
var n = long.Parse(line[0]);
var b = int.Parse(line[1]);
if (b == 1)
{
Console.WriteLine(n);
}
var result = 0;
var tens = 1;
if (n % 10 > nums[b])
{
result += nums[b] - 1;
}
for (int j = 0; n > 0; j++)
{
var xd = n % 10;
n /= 10;
tens *= nums[b - 1];
result += (nums[b - 1] - 1);
}
Console.WriteLine(n);
}
}
}