您的位置:首页 > 其它

算法竞赛入门经典第三章3-10 Box UVA - 1587

2018-01-03 13:45 239 查看
习题3-10

https://vjudge.net/problem/UVA-1587

#include<iostream>
using namespace std;
int main() {
int a[6][2],cnt;
int sta[15], top;//sta[1...14]
while (cin >> a[0][0] >> a[0][1]) {
top = 0;
int vis[10006] = {};
vis[a[0][0]] = 1; sta[++top] = a[0][0];
if (!vis[a[0][1]]++) sta[++top] = a[0][1];
for (int i = 1; i < 6; ++i){
cin >> a[i][0] >> a[i][1];
if (!vis[a[i][0]]++)  sta[++top] = a[i][0];
if (!vis[a[i][1]]++)  sta[++top] = a[i][1];
}
if (top == 1) cout << "POSSIBLE" << endl;//一个数字
else if (top == 2 && (vis[sta[1]]==8|| vis[sta[1]] == 4)) {//1*1 2个 1*2 4个
int nn = 0;
for (int i = 0; i < 6; ++i)
if (a[i][0] == a[i][1]) ++nn;
if (nn != 2)cout << "IMPOSSIBLE" << endl;
else cout << "POSSIBLE" << endl;
}
else if (top == 3 && vis[sta[1]]==4 && vis[sta[2]]==4) {//3个数字
bool flag = true;
for (int i = 0; i < 6; ++i)
if (a[i][0] == a[i][1]) { flag = false; break; }
if(flag) cout << "POSSIBLE" << endl;
else cout << "IMPOSSIBLE" << endl;
}
else
cout << "IMPOSSIBLE" << endl;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: