ZOJ
判断6个矩形能否组成一个盒子,应该有很多种方法,随便想了一种
#include<stdio.h>
#include<stdlib.h>struct Pallet
{int w;int h;
};typedef struct Pallet *Palptr;int cmp2659(const void *i1, const void *i2)
{Palptr p1 = (Palptr) i1;Palptr p2 = (Palptr) i2;if (p1->w != p2->w)return p1->w - p2->w;elsereturn p1->h - p2->h;
}int main()
{int a, b;Palptr array = malloc(6 * sizeof(struct Pallet));while (scanf("%d %d", &a, &b) != EOF){int i;array[0].w = a < b ? a : b;array[0].h = a > b ? a : b;for (i = 1; i < 6; i++){scanf("%d %d", &a, &b);array[i].w = a < b ? a : b;array[i].h = a > b ? a : b;}qsort(array, 6, sizeof(struct Pallet), cmp2659);if (array[0].w == array[1].w && array[1].w == array[2].w&& array[2].w == array[3].w && array[0].h == array[1].h&& array[1].h == array[4].w && array[4].w == array[5].w&& array[2].h == array[3].h && array[3].h == array[4].h&& array[4].h == array[5].h)printf("POSSIBLE\n");elseprintf("IMPOSSIBLE\n");}free(array);return 0;
}
ZOJ
判断6个矩形能否组成一个盒子,应该有很多种方法,随便想了一种
#include<stdio.h>
#include<stdlib.h>struct Pallet
{int w;int h;
};typedef struct Pallet *Palptr;int cmp2659(const void *i1, const void *i2)
{Palptr p1 = (Palptr) i1;Palptr p2 = (Palptr) i2;if (p1->w != p2->w)return p1->w - p2->w;elsereturn p1->h - p2->h;
}int main()
{int a, b;Palptr array = malloc(6 * sizeof(struct Pallet));while (scanf("%d %d", &a, &b) != EOF){int i;array[0].w = a < b ? a : b;array[0].h = a > b ? a : b;for (i = 1; i < 6; i++){scanf("%d %d", &a, &b);array[i].w = a < b ? a : b;array[i].h = a > b ? a : b;}qsort(array, 6, sizeof(struct Pallet), cmp2659);if (array[0].w == array[1].w && array[1].w == array[2].w&& array[2].w == array[3].w && array[0].h == array[1].h&& array[1].h == array[4].w && array[4].w == array[5].w&& array[2].h == array[3].h && array[3].h == array[4].h&& array[4].h == array[5].h)printf("POSSIBLE\n");elseprintf("IMPOSSIBLE\n");}free(array);return 0;
}
发布评论