Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: utf-8
Méret: 3 KB
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Jegtomb
{
class Coords
{
public int x, y, z;
public Coords(int _x, int _y, int _z)
{
x = _x;
y = _y;
z = _z;
}
}
class Program
{
private int n, m, k;
private bool[, ,] ice;
private Queue<Coords> q = new Queue<Coords>();
private int[] time = new int[100];
public Program()
{
StreamReader ins = new StreamReader("jegtomb8.be");
StreamWriter outs = new StreamWriter("jegtomb8.ki");
string[] fLine = ins.ReadLine().Split(' ');
m = int.Parse(fLine[0]);
n = int.Parse(fLine[1]);
k = int.Parse(fLine[2]);
ice = new bool[n, m, k];
string line;
for (int l = 0; l < k; l++)
for (int j = 0; j < m; j++)
{
line = ins.ReadLine();
for (int i = 0; i < n; i++)
{
if (line[i] == '1')
{
ice[i, j, l] = true;
q.Enqueue( new Coords(i,j,l) );
}
else ice[i, j, l] = false;
}
}
melt( outs );
}
private void melt( StreamWriter outs )
{
Queue<Coords> q2;
Queue<Coords> q3 = new Queue<Coords>();
Coords c;
int i = 0;
time[0] = q.Count;
while (q.Count != 0)
{
q2 = new Queue<Coords>();
while (q.Count != 0)
{
c = q.Dequeue();
if (enoughAir(c.x, c.y, c.z))
{
q3.Enqueue(c);
}
else
{
q2.Enqueue(c);
}
}
while (q3.Count != 0)
{
c = q3.Dequeue();
ice[c.x, c.y, c.z] = false;
}
time[++i] = q2.Count;
q = q2;
}
outs.WriteLine( i );
for( int j=0; j < i; j++ )
{
outs.WriteLine(time[j]);
}
outs.Close();
}
private bool enoughAir(int i, int j, int l)
{
int air = 0;
if (l > 0 && !ice[i, j, l - 1]) air++;
if (l < k - 1 && !ice[i, j, l + 1]) air++;
if (!ice[i - 1, j, l]) air++;
if (!ice[i + 1, j, l]) air++;
if (!ice[i, j + 1, l]) air++;
if (!ice[i, j - 1, l]) air++;
return air >= 3;
}
static void Main(string[] args)
{
new Program();
}
}
}