Пример #1
0
        private static void readFromConsole()
        {
            var solver = new Solver2();
            var line1 = System.Console.ReadLine().Trim().Split(' ');
            var H = Int32.Parse(line1[0]);
            var W = Int32.Parse(line1[1]);
            var fields = new String[H];
            for (var i = 0; i < H; ++i) {
                var line = System.Console.ReadLine().Trim();
                fields[i] = line;
            }
            var line2 = System.Console.ReadLine().Trim();
            var N = Int32.Parse(line2);
            var widgets = new Widget[N];
            for(var i = 0; i < N; ++i) {
                var line = System.Console.ReadLine().Trim().Split(' ');
                var S = Int32.Parse(line[0]);
                var T = Int32.Parse(line[1]);
                widgets[i] = new Widget(S, T);
            }

            var answers = solver.solve(fields, widgets);
            foreach(int answer in answers)
                System.Console.WriteLine(answer);
        }
Пример #2
0
 private int solve(String[] fields, Widget widget)
 {
     int answer = 0;
     for(int i = 0; i < fields.Length - widget.S; ++i) {
         for(int j = 0; j < fields[i].Length - widget.T; ++j) {
             if(canArrange(fields, widget, i, j)) {
                 ++answer;
             }
         }
     }
     return answer;
 }
Пример #3
0
 private bool canArrange(String[] fields, Widget widget, int i, int j)
 {
     bool result = true;
     for(int x = j; x <= j + widget.T; ++x) {
         for(int y = i; y <= i + widget.S; ++y) {
             // System.Console.Write("(" + y.ToString() + ", " + x.ToString() + "), ");
             result = result && fields[y][x] == '0';
         }
     }
     // System.Console.WriteLine("canArray(" + i.ToString() + ", " + j.ToString() + ") = " + result.ToString());
     return result;
 }
Пример #4
0
 public IEnumerable<int> solve(String[] fields, Widget[] widgets)
 {
     foreach(Widget widget in widgets)
         yield return solve(fields, widget);
 }
Пример #5
0
 public bool canArrange(Widget widget)
 {
     return widget.S < widthList.Length && widthList[widget.S] >= widget.T;
 }