3-10

#define _CRT_SECURE_NO_WARNINGS 

#include <cstdio>

using namespace std;

int main()
{
    int w[6];
    int h[6];
    while (scanf("%d%d", &w[0], &h[0])){
        for (int i = 1; i < 6; i++)
            scanf("%d%d", &w[i], &h[i]);

        for (int i = 0; i < 6; i++){
            if (w[i] > h[i]){
                int tmp = w[i];
                w[i] = h[i];
                h[i] = tmp;
            }
        }

        // remove duplicates
        int wi[3] = { 0 };
        int hi[3] = { 0 };
        int k = 0;
        for (int i = 0; i < 6; i++){
            for (int j = i + 1; j < 6; j++){
                if (w[i] > 0 && w[i] == w[j] && h[i] == h[j]){
                    wi[k] = w[i];
                    hi[k] = h[i];
                    k++;
                    w[i] = w[j] = h[i] = h[j] = -1;
                    break;
                }
            }
        }

        //printf("### %d %d %d %d %d %d\n", wi[0], hi[0], wi[1], hi[1], wi[2], hi[2]);

        if (wi[0] == 0 || wi[1] == 0 || wi[2] == 0){
            printf("IMPOSSIBLE\n");
            continue;
        }

        for (int i = 0; i < 3; i++){
            for (int j = 0; j < 3; j++){
                if (wi[i] > 0 && i != j && wi[i] == wi[j]){
                    wi[i] = wi[j] = -1;
                }
                if (wi[i] > 0 && i != j && wi[i] == hi[j]){
                    wi[i] = hi[j] = -1;
                }
                if (hi[i] > 0 && i != j && hi[i] == hi[j]){
                    hi[i] = hi[j] = -1;
                }
            }
        }

        //printf("### %d %d %d %d %d %d\n", wi[0], hi[0], wi[1], hi[1], wi[2], hi[2]);

        bool possible = true;
        for (int i = 0; i < 3; i++){
            if (wi[i] != -1 || hi[i] != -1){
                possible = false;
                break;
            }
        }

        if (possible)
            printf("POSSIBLE\n");
        else
            printf("IMPOSSIBLE\n");

    }

    return 0;
}

 

posted @ 2016-07-25 20:45  PatrickZhou  阅读(110)  评论(0编辑  收藏  举报