一开始用set存xjb分类讨论,然后wa,
然后简化了一点,改用vector,然wa
最后又发现没有初始化,然wa
wa了一个半小时
最后看了题解orz
然后找了一组样例把自己的代码改对了
/*
1 1
1 1
1 1
1 1
1 2
1 2
*/
正统题解:不妨设三条边为a<=b<=c, 那么对每个面(边对)sort后,必然得到 ab ab ac ac bc bc 然后照着这个序列写六个判断就好了orz
#define _CRT_SECURE_NO_WARNINGS #include<cmath> #include<iostream> #include<stdio.h> #include<algorithm> #include<cstring> #include<stack> #include<vector> #include<string.h> #include<queue> #include<string> #include<set> #include<map> using namespace std; typedef long long ll; #define mod 1000000007 #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) #define eps 1e-6 #define pb push_back #define mp make_pair #define x first #define y second pair<int, int> a[7]; int main() { while (cin >> a[1].x >> a[1].y){ rep(i, 2, 6)scanf("%d%d", &a[i].x, &a[i].y); rep(i, 1, 6)if(a[i].x>a[i].y)swap(a[i].x,a[i].y); sort(a + 1, a + 7); puts(a[1] == a[2] && a[3] == a[4] && a[5] == a[6] && a[1].x==a[3].x&&a[3].y==a[5].y&&a[5].x==a[1].y?"POSSIBLE":"IMPOSSIBLE"); } } /* POSSIBLE IMPOSSIBLE */
第一版代码,先判每个面出现了两遍,再把不同的三个面找出来,按有几个面是正方形分类
#define _CRT_SECURE_NO_WARNINGS #include <cmath> #include <iostream> #include <stdio.h> #include<algorithm> #include <map> #include <cstring> #include <time.h> #include <string> #include <vector> #include <set> using namespace std; #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) const double pi = acos(-1.0); const int maxn = 100 + 5; int n,m; int main() { int x, y; while (cin >> x >> y){ set<int> S[7]; vector < set<int>> V; S[1].insert(x), S[1].insert(y); rep(i, 2, 6) { cin >> x >> y; S[i].insert(x), S[i].insert(y); } int f[7]; mmm(f, 0); int vis[7]; mmm(vis, 0); rep(i, 1, 6)rep(j, 1, 6)if (i != j) { if (S[i] == S[j]) { f[i] = 1; if (!vis[i]&&!vis[j]) { V.push_back(S[i]); vis[j] = 1; vis[i] = 1;} } } rep(i, 1, 6)if (!f[i]) { f[0] = 1; } if (f[0] == 1) { puts("IMPOSSIBLE"); continue; } int cnt=0; rep(i, 0, 2)if (V[i].size() == 1)cnt++; if (cnt == 3) { if (V[1] == V[0] && V[1] == V[2]) puts("POSSIBLE"); else puts("IMPOSSIBLE"); continue; } if (cnt == 1) { vector < set<int>> T; for (auto t : V)if (t.size() == 2) { T.push_back(t); } if(*T.begin()==*T.rbegin()) { puts("POSSIBLE"); continue; }else { puts("IMPOSSIBLE"); continue; } } if(cnt==2) { puts("IMPOSSIBLE"); continue; } if (cnt == 0) { int ok = 1; vector < int> T; rep(i, 1, 2)if (*V[0].begin() == *V[i].begin())T.push_back(*V[i].rbegin()); else if (*V[0].begin() == *V[i].rbegin())T.push_back(*V[i].begin()); rep(i, 1, 2)if (*V[0].rbegin() == *V[i].begin())T.push_back(*V[i].rbegin()); else if (*V[0].rbegin() == *V[i].rbegin())T.push_back(*V[i].begin()); //else ok = 0; if(T.size()!=2){ puts("IMPOSSIBLE"); continue; } if(T.front()!=T.back()) { puts("IMPOSSIBLE"); continue; } else { puts("POSSIBLE"); continue; } } } cin >> n; return 0; } /* 1 1 2 1 2 1 1 1 1 1 1 1 */
第二版代码:用vector存,并且简化了分类:要么可以 要么不可能//废话
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> #include<iostream> #include<queue> #include<set> #include<vector> using namespace std; typedef long long ll; #define rep(i,t,n) for(int i =(t);i<=(n);++i) #define per(i,n,t) for(int i =(n);i>=(t);--i) #define mmm(a,b) memset(a,b,sizeof(a)) int main() { int x, y; while (cin >> x >> y) { vector < vector<int>> V; vector<int> v[7]; if (x > y)swap(x, y); v[1].push_back(x); v[1].push_back(y); rep(i, 2, 6) { cin >> x >> y; if (x > y)swap(x, y); v[i].push_back(x); v[i].push_back(y); } int f[7]; int vis[7]; mmm(vis, 0); mmm(f, 0); rep(i, 1, 6)rep(j, 1, 6)if (i != j) { if (v[i] == v[j]) { f[i] = 1; if (!vis[i]&&!vis[j]) { V.push_back(v[i]); vis[j] = 1; vis[i] = 1;} } } rep(i, 1, 6)if (!f[i]) { f[0] = 1; } if (f[0] == 1) { puts("IMPOSSIBLE"); continue; } int ok = 1; int t = 0; int x = 2; if (V[0].front() == V[1].front())t = V[1].back(); else if (V[0].front() == V[1].back())t = V[1].front(); else { x = 1; if (V[0].front() == V[2].front())t = V[2].back(); else if (V[0].front() == V[2].back())t = V[2].front(); else ok = 0; } int t2 = 0; if (t == V[x].front())t2 = V[x].back(); else if (t == V[x].back())t2 = V[x].front(); else { ok = 0; } if (t2 != V[0].back())ok = 0; if (ok)puts("POSSIBLE"); else puts("IMPOSSIBLE"); } return 0; }