1587 - Box
来源:互联网 发布:火车购票软件哪款好用 编辑:程序博客网 时间:2024/06/02 04:07
Ivan works at afactory that produces heavy machinery. He has a simple job -- he knocks upwooden boxes of different sizes to pack machinery for delivery to thecustomers. Each box is a rectangular parallelepiped. Ivan uses six rectangularwooden pallets to make a box. Each pallet is used for one side of the box.
Joe deliverspallets for Ivan. Joe is not very smart and often makes mistakes -- he bringsIvan pallets that do not fit together to make a box. But Joe does not trustIvan. 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 believesthat computers never make mistakes. Ivan has decided to use this for his ownadvantage. Ivan asks you to write a program that given sizes of six rectangularpallets tells whether it is possible to make a box out of them.
Input
Input filecontains several test cases. Each of them consists of six lines. Each linedescribes one pallet and contains two integer numbers w and h ( 1w, h10 000) -- width andheight of the pallet in millimeters respectively.
Output
For each testcase, print one output line. Write a single word `POSSIBLE' to the output file if it is possible tomake a box using six given pallets for its sides. Write a single word `IMPOSSIBLE' if it is notpossible 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<iostream>
#include<cstdio>
using namespacestd;
int main()
{
int arr[6][2];
while(cin>>arr[0][0]>>arr[0][1]&&arr[0][0]!=EOF)
{
for(int i=1;i<6;i++)
{
cin>>arr[i][0]>>arr[i][1];
}
int dou=0;
for(int i=0;i<5&&arr[i][0]!=0;i++)
{
int check=0;
for(intj=i+1;j<6&&check==0;j++)
{
for(int k=0;k<2;k++)
{
if(arr[i][0]==arr[j][k])
{
if(arr[i][0]*arr[i][1]==arr[j][0]*arr[j][1])
{
dou++;
check=1;
arr[i][0]=0;
arr[i][1]=0;
arr[j][0]=0;
arr[j][1]=0;
break;
}
}
}
}
}
cout<<dou<<endl;
if(dou==3)
{
cout<<"POSSIBLE\n";
}
else
{
cout<<"IMPOSSIBLE\n";
}
}
}
#include<algorithm>
#include<iostream>
#include<vector>
using namespacestd;
struct Face
{
int h, w;
void make(int x, int y)
{
h = min(x,y);
w = max(x,y);
}
bool operator < (const Face& b)const
{
if (h == b.h)
{
return w < b.w;
}
else
{
return h < b.h;
}
}
bool operator == (const Face& b) const
{
return (h == b.h) && (w ==b.w);
}
};
vector<Face>A(6);
int test1()
{
for (int i = 0; i < 6; i += 2)
{
if (!(A[i]==A[i+1]))
{
return 0;
}
}
return 1;
}
int test2()
{
if (A[0].h==A[2].h &&A[0].w==A[4].h && A[2].w==A[4].w)
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int x, y;
while (cin >> x >> y)
{
A[0].make(x, y);
for (int i = 1; i < 6; i++)
{
cin >> x >> y;
A[i].make(x, y);
}
sort(A.begin(), A.end());
if (test1() && test2())
{
cout <<"POSSIBLE\n";
}
else
{
cout <<"IMPOSSIBLE\n";
}
}
return 0;
}
#include<cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
struct NODE
{
int h, w;
bool operator < (const NODE& rha)const{
if(h == rha.h) return w < rha.w;
return h < rha.h;
}
}a[10];
bool ok()
{
if(a[0].h != a[1].h || a[0].w != a[1].w)return false;
if(a[2].h != a[3].h || a[2].w != a[3].w)return false;
if(a[4].h != a[5].h || a[4].w != a[5].w)return false;
if(a[1].h != a[2].h) return false;
if(a[1].w != a[4].h) return false;
if(a[3].w != a[4].w) return false;
return true;
}
int main()
{
while(scanf("%d%d", &a[0].h,&a[0].w) != EOF)
{
if(a[0].h > a[0].w) swap(a[0].h,a[0].w);
for(int i = 1; i < 6; ++i)
{
scanf("%d%d",&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(ok()) puts("POSSIBLE");
else puts("IMPOSSIBLE");
}
return 0;
}
- 1587 - Box
- 1587 - Box
- 1587 - Box
- uva 1587 - Box
- uva 1587 - Box
- UVa 1587 - Box
- UVa 1587 - Box
- UVa 1587 Box
- Uva-1587-Box-AC
- UVA - 1587 Box
- UVa 1587 Box
- Box UVa 1587
- UVA - 1587 Box 麻烦
- UVa 1587 - Box
- UVa 1587 - Box
- UVa-1587 - Box
- UVa 1587 Box
- Uva - 1587 - Box
- 455 - Periodic Strings
- 1225 - Digit Counting
- 1368 - DNA Consensus String
- 1585—Score
- 1586—Molar mass
- 1587 - Box
- 1588 - Kickdown
- 10340 - All in All
- 11809 - Floating-Point Numbers
- 133 - The Dole Queue
- 213 - Message Decoding
- 使用JTable组件
- 489 - Hangman Judge
- 512 - Spreadsheet Tracking