본문 바로가기
Computer Science

DEPTH SQUARE plzrun

by OKOK 2019. 3. 11.

1. main 문 읽고

2. 알아서 판단해서 user 를 짜기

3. 어떤 문제인지 파악 가능?

4. 코드 길이는 매우 짧음

5. 높이, 그리고 문제 해석 가능?

6. 오버로딩, 클래스, 구조체 사용하는 방법 익히기 

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
#include <cstdio>
const int SIZE = 100;
const int NUM_RECT = 64;
const int MIN_RECT_SIZE = 10;
int COUNT, SCORE;
int seed = 1117;
 
int image[SIZE][SIZE];
extern int recog(int image[SIZE][SIZE]);
static int pseudo_rand(void) {
    seed = seed * 214013 + 2531011;
    return (seed >> 16& 0x7FFF;
}
 
void rect() {
    int sx, sy, ex, ey, tmp;
    while (true) {
        sx = pseudo_rand() % SIZE;
        ex = pseudo_rand() % SIZE;
        sy = pseudo_rand() % SIZE;
        ey = pseudo_rand() % SIZE;
 
        if (sx > ex) {
            tmp = sx;
            sx = ex;
            ex = tmp;
        }
 
        if (sy > ey) {
            tmp = sy;
            sy = ey;
            ey = tmp;
        }
        if (ex - sx < MIN_RECT_SIZE) continue;
        if (ey - sy < MIN_RECT_SIZE) continue;
        break;
    }
    int height = pseudo_rand() % 5 + 1;
    for (register int y = sy; y <= ey; y++)
        for (register int x = sx; x <= ex; x++)
            image[y][x] += height;
    if (ex - sx == ey - sy)
        COUNT++;
}
 
void _build() {
    for (int y = 0; y < SIZE; y++)
        for (int x = 0; x < SIZE; x++)
            image[y][x] = 0;
    COUNT = 0;
    for (int i = 0; i < NUM_RECT; i++) rect();
}
 
int main() {
    freopen("input.txt""r", stdin);
    scanf("%d"&seed);
    SCORE = 0;
    for (int T = 0; T < 3000; T++)
    {
        _build();
        if (recog(image) == COUNT) SCORE++;
    }
 
    if (SCORE >= 2700)
        printf("PASS\n");
    else
        printf("FAIL\n");
    //printf("RESULT: %d\n", SCORE);
 
    return 0;
}
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
const int SIZE = 100;
const int MIN_RECT_SIZE = 10;
int myimage[SIZE + 2][SIZE + 2];
int layer[SIZE + 2][SIZE + 2];
 
struct Point {
    int x, y;
    Point() {}
    Point(int x, int y) :x(x), y(y) {}
    bool operator<(const Point &rhs) const {
        if (x == rhs.x) return y<rhs.y;
        else return x<rhs.x;
    }
};
template <class T>
struct Queue {
    T arr[20001];
    int f, r;
    Queue() :f(0), r(0) {}
    void init() { f = r = 0; }
    void push(const T &x) { arr[r++= x; }
    T pop() { return arr[f++]; }
    bool empty() const { return f >= r; }
    int size() const { return r - f; }
};
Queue<Point> q;
int recog(int image[SIZE][SIZE]) {
    q.init();
    for (register int i = 0; i<SIZE + 2; i++) {
        myimage[i][0= myimage[0][i] = myimage[i][SIZE + 1= myimage[SIZE + 1][i] = 0;
        layer[i][0= layer[0][i] = layer[i][SIZE + 1= layer[SIZE + 1][i] = 0;
    }
    for (register int i = 0; i<SIZE; i++) {
        for (register int j = 0; j<SIZE; j++) {
            myimage[i + 1][j + 1= image[i][j];
        }
    }
 
    for (register int i = 1; i<SIZE + 2; i++) {
        for (register int j = 1; j<SIZE + 2; j++) {
            layer[i][j] = myimage[i][j] - myimage[i - 1][j] - myimage[i][j - 1+ myimage[i - 1][j - 1];
            if (layer[i][j]>0) q.push(Point(i, j));
        }
    }
    register int ans = 0;
    while (!q.empty()) {
        Point p = q.pop();
        for (register int len = MIN_RECT_SIZE + 1; p.x + len<SIZE + 2 && p.y + len<SIZE + 2; len++) {
            register int nx = p.x + len, ny = p.y + len;
            if (layer[nx][ny]>0 && layer[p.x][ny]<0 && layer[nx][p.y]<0) ans++;
        }
    }
    return ans;
}
 
cs

 


1117

'Computer Science' 카테고리의 다른 글

expert 제목 및 팁  (0) 2019.03.13
Disjoint-set Union-Find  (0) 2019.03.13
중고차 솔루션  (0) 2019.03.08
인터프리터 해적  (0) 2019.03.08
고속도로 건설 2 넌 is 뭔들  (0) 2019.03.06

댓글