Ivan works at a factory that produces heavy machinery. He has a simple job -- he knocks up wooden boxes of different sizes to pack machinery for delivery to the customers. Each box is a rectangular parallelepiped. Ivan uses six rectangular wooden pallets to make a box. Each pallet is used for one side of the box.
Joe delivers pallets for Ivan. Joe is not very smart and often makes mistakes -- he brings Ivan pallets that do not fit together to make a box. But Joe does not trust Ivan. It always takes a lot of time to explain Joe that he has made a mistake. Fortunately, Joe adores everything related to computers and sincerely believes that computers never make mistakes. Ivan has decided to use this for his own advantage. Ivan asks you to write a program that given sizes of six rectangular pallets tells whether it is possible to make a box out of them.
Input
Input file contains several test cases. Each of them consists of six lines. Each line describes one pallet and contains two integer numbers w and h ( 1w, h10 000) -- width and height of the pallet in millimeters respectively.
Output
For each test case, print one output line. Write a single word POSSIBLE' to the output file if it is possible to make a box using six given pallets for its sides. Write a single word
IMPOSSIBLE' if it is not possible to do so.
Sample Input
1345 2584
2584 683
2584 1345
683 1345
683 1345
2584 683
1234 4567
1234 4567
4567 4321
4322 4567
4321 1234
4321 1234
Sample Output
POSSIBLE
IMPOSSIBLE
题目类型:数学题
算法分析:由平行四面体的几何关系可知组成四面体的六个长方形必须两两长宽分别相等。这里将数据输入结构体数组后,将数组先按照h递增排序,然后按照w递增排序。然后进行简单的判断即可。注意重载小于号的方法及进行递增排序的方法,下面第一个代码是更好的实现
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 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
/************************************************** filename :p.cpp author :maksyuki created time :2017/12/3 15:11:05 last modified :2017/12/3 15:17:15 file location :C:\Users\abcd\Desktop\TheEternalPoet ***************************************************/ #pragma comment(linker, "/STACK:102400000,102400000") #include <set> #include <bitset> #include <list> #include <map> #include <stack> #include <queue> #include <deque> #include <string> #include <vector> #include <ios> #include <iostream> #include <fstream> #include <sstream> #include <iomanip> #include <algorithm> #include <utility> #include <complex> #include <numeric> #include <functional> #include <cmath> #include <ctime> #include <climits> #include <cstdarg> #include <cstdio> #include <cstdlib> #include <cstring> #include <cctype> #include <cassert> using namespace std; #define CFF freopen ("in", "r", stdin) #define CFO freopen ("out", "w", stdout) #define CPPFF ifstream cin ("in") #define CPPFO ofstream cout ("out") #define DB(ccc) cout << #ccc << " = " << ccc << endl #define DBT printf("time used: %.2lfs\n", (double) clock() / CLOCKS_PER_SEC) #define PB push_back #define MP(A, B) make_pair(A, B) typedef long long LL; typedef unsigned long long ULL; typedef double DB; typedef pair <int, int> PII; typedef pair <int, bool> PIB; const int INF = 0x7F7F7F7F; const int MOD = 1e9 + 7; const double EPS = 1e-10; const double PI = 2 * acos (0.0); const int maxn = 1e5 + 6666; struct node { int a, b; }; node v[maxn]; bool cmp(const node &a, const node &b) { if(a.a != b.a) return a.a < b.a; return a.b < b.b; } int main() { #ifdef LOCAL CFF; //CFO; #endif int tmpa, tmpb; while(scanf(" %d", &tmpa) != EOF) { scanf(" %d", &tmpb); v[1].a = min(tmpa, tmpb); v[1].b = max(tmpa, tmpb); for(int i = 2; i <= 6; i++) { scanf(" %d %d", &tmpa, &tmpb); v[i].a = min(tmpa, tmpb); v[i].b = max(tmpa, tmpb); } sort(v + 1, v + 1 + 6, cmp); if(v[1].a == v[2].a && v[1].a == v[3].a && v[1].a == v[4].a && v[1].b == v[2].b && v[1].b == v[5].a && v[1].b == v[6].a && v[3].b == v[4].b && v[3].b == v[5].b && v[3].b == v[6].b) puts("POSSIBLE"); else puts("IMPOSSIBLE"); } return 0; } |
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 |
#include <cstdio> #include <iostream> #include <fstream> #include <algorithm> using namespace std; struct point { int h, w; bool operator < (const point &A) const { if (h == A.h) return w < A.w; return h < A.h; } }a[16]; bool panduan () { int i; for (i = 0; i < 5; i += 2) if (a[i].h != a[i+1].h || a[i].w != a[i+1].w) return false; if (a[1].h != a[2].h) return false; if (a[1].w != a[4].h) return false; if (a[2].w != a[4].w) return false; return true; } int main() { //ifstream cin ("aaa.txt"); while (cin >> a[0].h >> a[0].w) { if (a[0].h > a[0].w) swap (a[0].h, a[0].w); int i; for (i = 1; i < 6; i++) { cin >> a[i].h >> a[i].w; if (a[i].h > a[i].w) swap (a[i].h, a[i].w); } sort (a, a + 6); if (panduan ()) cout << "POSSIBLE" <<endl; else cout << "IMPOSSIBLE" << endl; } return 0; } |
- « 上一篇:uva1584
- uva1588:下一篇 »