Problem 019 —— UVa 1587 - Box
2014-12-10 16:09
393 查看
Ivan works at a factory that produces heavy machinery. He hasa simple job -- he knocks up wooden boxes of different sizesto pack machinery for delivery to the customers. Each boxis a rectangular parallelepiped. Ivan uses six rectangular wooden palletsto
make a box. Each pallet is used for one side of the box.
Joe delivers pallets for Ivan. Joe is not very smart andoften makes mistakes -- he brings Ivan pallets that do not fittogether to make a box. But Joe does not trust Ivan. It alwaystakes a lot of time to explain Joe that he has made a mistake.Fortunately, Joe
adores everything related to computers and sincerelybelieves that computers never make mistakes. Ivan has decided touse this for his own advantage. Ivan asks you to writea program that given sizes of six rectangular palletstells whether it is possible to make
a box out of them.
h (1
w,h
10 000)
--width and height of the pallet in millimeters respectively.
make a box. Each pallet is used for one side of the box.
Joe delivers pallets for Ivan. Joe is not very smart andoften makes mistakes -- he brings Ivan pallets that do not fittogether to make a box. But Joe does not trust Ivan. It alwaystakes a lot of time to explain Joe that he has made a mistake.Fortunately, Joe
adores everything related to computers and sincerelybelieves that computers never make mistakes. Ivan has decided touse this for his own advantage. Ivan asks you to writea program that given sizes of six rectangular palletstells 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 andcontains two integer numbersw andh (1
w,h
10 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 possibleto 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
#include"cstdio" #include"iostream" #include"cstring" #include"cstdlib" #include <algorithm> using namespace std; int box[6][2]; int x[3][2]; int pd[6]; int main() { while(cin >> box[0][0] >> box[0][1]){ for(int i=1;i<6;i++) cin >> box[i][0] >> box[i][1]; for(int i=0;i<6;i++){ if(box[i][0]>box[i][1]){ int t=box[i][0]; box[i][0]=box[i][1]; box[i][1]=t; } } int k=0; memset(x,0,sizeof(x)); for(int i=0;i<5;i++) for(int j=i+1;j<6;j++){ if(box[i][0]==box[j][0]&&box[i][1]==box[j][1]&&box[i][0]){ x[k][0]=box[i][0],x[k++][1]=box[i][1]; box[j][0]=box[j][1]=box[i][1]=box[i][0]=0; } } k=0; memset(pd,0,sizeof(pd)); for(int i=0;i<3;i++) for(int j=0;j<2;j++) pd[k++]=x[i][j]; sort(pd,pd+6); if(pd[0]==0) printf("IMPOSSIBLE\n"); else if(pd[0]==pd[1]&&pd[2]==pd[3]&&pd[4]==pd[5]) printf("POSSIBLE\n"); else printf("IMPOSSIBLE\n"); memset(box,0,sizeof(box)); } return 0; }
相关文章推荐
- UVA 1587 Box
- UVa 1587 Box (判断长方体)
- UVa1587 - Box
- UVa Problem 10215 The Largest/Smallest Box... (最大/最小的盒子)
- Uva-1587-Box-AC
- 算法竞赛入门经典(紫书)第三章——Box UVA-1587
- UVA 1587 BOX
- UVA 1587 - Box
- uva 1587 Box(思路)
- UVa 1587 Box
- UVA - 1587 Box
- ???习题3-10 UVa1587 Box
- UVa1587--Box--盒子(代码超简洁)
- UVa_1587 - Box
- Uva1587 - Box
- Box UVA - 1587
- UVA - 1587 Box
- UVa 1587 - Box
- UVa 1587 Box
- UVA 1587-Box