QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673407#6563. Four Squarestudy_to_deathAC ✓0ms3724kbC++146.4kb2024-10-24 22:13:402024-10-24 22:13:42

Judging History

你现在查看的是最新测评结果

  • [2024-10-24 22:13:42]
  • 评测
  • 测评结果:AC
  • 用时:0ms
  • 内存:3724kb
  • [2024-10-24 22:13:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int sqr;
struct node
{
    int w, h;
} cube[5];
int p[5];
int flag, w, h;
int num[1005];
int ff[5];

void dfs(int step, int f)
{
    if (flag)
        return;
    ff[step] = f;
    if (step == 4)
    {
        w = h = 0;
        int x = 0, y = 0;
        for (int i = 1; i <= 2; i++)
        {
            if (ff[i])
            {
                x += cube[p[i]].h;
                y = max(y, cube[p[i]].w);
            }
            else
            {
                y = max(y, cube[p[i]].h);
                x += cube[p[i]].w;
            }
        }
        w = max(w, x);
        h = y;
        x = y = 0;
        for (int i = 3; i <= 4; i++)
        {
            if (ff[i])
            {
                x += cube[p[i]].h;
                y = max(y, cube[p[i]].w);
            }
            else
            {
                y = max(y, cube[p[i]].h);
                x += cube[p[i]].w;
            }
        }
        w = max(w, x);
        h += y;
        if (w * h == sqr)
        {
            // cout << w << " " << h << "****" << endl;
            flag = 1;
        }

        return;
    }
    dfs(step + 1, 1);
    dfs(step + 1, 0);
}

signed main()
{
    for (int i = 1; i <= 4; i++)
    {
        p[i] = i;
        cin >> cube[i].w >> cube[i].h;
        num[cube[i].w]++;
        num[cube[i].h]++;
        if (cube[i].w == cube[i].h)
            num[cube[i].w]--;
    }
    for (int i = 1; i <= 4; i++)
    {
        sqr += cube[i].w * cube[i].h;
    }
    int t = sqrt(sqr);
    if (t * t != sqr)
    {
        cout << 0 << endl;
        return 0;
    }

    for (int i = 1; i <= 1000; i++)
    {
        if (num[i] == 4)
        {
            cout << 1 << endl;
            return 0;
        }
    }

    for (int i = 1; i <= 1000; i++)
    {
        if (num[i] == 3)
        {
            int len = 0, x;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].w == i)
                    len += cube[j].h;
                else if (cube[j].h == i)
                    len += cube[j].w;
                else
                    x = j;
            }
            if (cube[x].h == len || cube[x].w == len)
            {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    // cout << "***" << endl;
    do
    {
        dfs(1, 0);
        dfs(1, 1);
        if (flag)
            break;
    } while (next_permutation(p + 1, p + 5));
    if (flag)
    {
        cout << 1 << endl;
        return 0;
    }
    for (int i = 1; i < 1001; i++)
    {
        if (num[i] == 2)
        {
            int len = 0, x = 0, y = 0;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].w == i)
                    len += cube[j].h;
                else if (cube[j].h == i)
                    len += cube[j].w;
                else
                {
                    if (!x)
                        x = j;
                    else
                        y = j;
                }
            }
            int len1 = 0;
            if (i != t)
                continue;
            if (cube[x].h == cube[y].h)
                len1 = cube[x].w + cube[y].w;
            if (len1 == len || len1 == i)
                flag = 1;
            if (cube[x].h == cube[y].w)
                len1 = cube[x].w + cube[y].h;
            if (len1 == len || len1 == i)
                flag = 1;
            if (cube[x].w == cube[y].w)
                len1 = cube[x].h + cube[y].h;
            if (len1 == len || len1 == i)
                flag = 1;
            if (cube[x].w == cube[y].h)
                len1 = cube[x].h + cube[y].w;
            if (len1 == len || len1 == i)
                flag = 1;
            if (flag)
            {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    // cout << "****" << endl;
    for (int i = 1; i <= 1000; i++)
    {
        if (num[i] == 2)
        {
            int x = 0, y = 0, len = 0;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].h == i)
                    len += cube[j].w;
                else if (cube[j].w == i)
                    len += cube[j].h;
                else
                {
                    if (!x)
                        x = j;
                    else
                        y = j;
                }
            }
            if (len == cube[x].h)
            {
                if (i + cube[x].w == cube[y].h || i + cube[x].w == cube[y].w)
                    flag = 1;
            }
            else if (len == cube[x].w)
            {
                if (i + cube[x].h == cube[y].h || i + cube[x].h == cube[y].w)
                    flag = 1;
            }
            if (len == cube[y].h)
            {
                if (i + cube[y].w == cube[x].h || i + cube[y].w == cube[x].w)
                    flag = 1;
            }
            else if (len == cube[y].w)
            {
                if (i + cube[y].h == cube[x].h || i + cube[y].h == cube[x].w)
                    flag = 1;
            }
        }
        else
        {
            int x = 0, len[2] = {0}, mx = 0;
            len[0] = 2 * x;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].w == i)
                {
                    if (cube[mx].h < cube[j].h)
                        mx = j;
                }
                else if (cube[j].h == i)
                {
                    if (cube[mx].w < cube[mx].h)
                        mx = j;
                }
                else
                {
                    x = j;
                }
            }
            for (int j = 1; j <= 4; j++)
            {
                if (j == x || j == mx)
                    continue;
                if (cube[j].h == i)
                    len[1] += cube[j].w;
                else if (cube[j].w == i)
                    len[1] += cube[j].h;
            }
            if (len[0] == cube[x].h || len[0] == cube[x].w)
            {
                if (len[1] == cube[mx].h || len[1] == cube[mx].w)
                    flag = 1;
            }
        }
        // cout << "****" << endl;
        if (flag)
        {
            cout << 1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3604kb

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

2 8
2 8
2 8
2 8

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

5 3
5 5
3 3
3 5

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

1 2
4 8
16 32
64 128

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

4 4
2 1
4 4
2 1

output:

0

result:

ok single line: '0'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

995 51
559 565
154 536
56 780

output:

0

result:

ok single line: '0'

Test #8:

score: 0
Accepted
time: 0ms
memory: 3684kb

input:

391 694
540 42
240 937
691 246

output:

0

result:

ok single line: '0'

Test #9:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

519 411
782 710
299 45
21 397

output:

0

result:

ok single line: '0'

Test #10:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

96 960
948 18
108 82
371 576

output:

0

result:

ok single line: '0'

Test #11:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

3 2
4 3
3 1
1 4

output:

0

result:

ok single line: '0'

Test #12:

score: 0
Accepted
time: 0ms
memory: 3724kb

input:

4 3
1 2
4 4
3 2

output:

0

result:

ok single line: '0'

Test #13:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

4 4
1 3
5 4
2 5

output:

0

result:

ok single line: '0'

Test #14:

score: 0
Accepted
time: 0ms
memory: 3680kb

input:

1000 1000
1000 1000
1000 1000
1000 1000

output:

1

result:

ok single line: '1'

Test #15:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

1000 999
998 1000
997 1000
997 997

output:

1

result:

ok single line: '1'

Test #16:

score: 0
Accepted
time: 0ms
memory: 3668kb

input:

1 3
3 3
3 3
4 7

output:

1

result:

ok single line: '1'

Test #17:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

2 5
5 4
7 1
6 2

output:

1

result:

ok single line: '1'

Test #18:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

12 2
12 7
7 12
16 4

output:

1

result:

ok single line: '1'

Test #19:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

7 2
2 14
5 14
7 12

output:

1

result:

ok single line: '1'

Test #20:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

32 36
5 1
1 37
35 5

output:

1

result:

ok single line: '1'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3488kb

input:

28 30
30 1
31 1
2 30

output:

1

result:

ok single line: '1'

Test #22:

score: 0
Accepted
time: 0ms
memory: 3508kb

input:

66 68
9 11
7 66
9 64

output:

1

result:

ok single line: '1'

Test #23:

score: 0
Accepted
time: 0ms
memory: 3596kb

input:

59 44
25 44
40 32
40 52

output:

1

result:

ok single line: '1'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

4 4
2 3
4 2
3 2

output:

1

result:

ok single line: '1'