UVa Box 1587

水题

注意点:

· 长宽不等
· 三组不同
· 三个不同的面两两包含共同边

#include
#include
#include
using namespace std;

int w[10], h[10];
int a[10];

void solve(){
    memset(a, 0, sizeof(a));
    int cnt = 0;
    int a1[5];
    memset(a1, 0, sizeof(a1));
    for(int i = 0; i < 6; ++i){
        int flag = true;
        if(a[i] != 0)
            continue;
        for(int j = i + 1; j < 6; ++j){
            if(w[i] == w[j] && h[i] == h[j]){
                flag = false;
                a1[cnt++] = i;
                a[i] = 1;
                a[j] = 1;
                break;
            }
        }
        if(flag){
            printf("IMPOSSIBLE\n");
            return ;
        }
    }
    bool flag = false;
    if(w[a1[0]] == w[a1[1]] || h[a1[0]] == h[a1[1]] || w[a1[0]] == h[a1[1]] || h[a1[0]] == w[a1[1]]){
        if(w[a1[0]] == w[a1[2]] || h[a1[0]] == h[a1[2]] || w[a1[0]] == h[a1[2]] || h[a1[0]] == w[a1[2]]){
            if(w[a1[1]] == w[a1[2]] || h[a1[1]] == h[a1[2]] || w[a1[1]] == h[a1[2]] || h[a1[1]] == w[a1[2]]){
                flag = true;
            }
        }
    }
    if(flag)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
}

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

    return 0;
}

你可能感兴趣的:(【OJ】)