hiho week 177 register

Ended

Participants:499

Verdict:Accepted
Score:100 / 100
Submitted:2017-11-21 14:24:30

Lang:GCC

Edit
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
#include <stdio.h>
int n, m, x1, y1, x2, y2;
int width[21];
int foo()
{
    int h = n, x = 0, w = width[n] * 5, count = 0;
    while (h > 1) {
        if (x > x2) break;
        else if (x >= x1) {
            if (y2 >= -x && y1 <= x) {
                int ly = y1 >= -x ? y1 : -x;
                int ry = y2 <= x ? y2 : x;
                int left = (ly + x + w - 1) / w * w;
                int right = (ry + x) / w * w;
                count += (right - left) / w + 1;
            }
        }
        x += width[h] - width[h - 1];
        w = 2 * (width[h] - width[h - 1]);
        --h;
    }
    if (h == 1 && x <= x2) {
        int ly = y1 >= -x ? y1 : -x;
        int ry = y2 <= x ? y2 : x;
        int left = (ly + x + 5) / 6 * 6;
        int right = (ry + x) / 6 * 6;
        count += (right - left) / 6 * 2;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX