首先,两个骰子等价意味着每个对立面都一一对应。
原题链接:骰子涂色 Cube painting - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)
这里我采用了map<pair<char,char>,int>的方法。我感觉相交于题解的桶记录更加的巧妙(骚),而且代码也简洁了一点。
主要代码:
#include<bits/stdc++.h> using namespace std; typedef pair<char,char> Pos; map<Pos,int> map1,map2; void process(char s1,char s2,bool s){ if (s){ if (s1>s2) map1[Pos(s2,s1)]++; else map1[Pos(s1,s2)]++; } else { if (s1>s2) map2[Pos(s2,s1)]++; else map2[Pos(s1,s2)]++; } } int main(){ string s; while (cin>>s){ process(s[0],s[5],true); process(s[1],s[4],true); process(s[2],s[3],true); process(s[6],s[11],false); process(s[7],s[10],false); process(s[8],s[9],false); bool m=true; for (map<Pos,int>::iterator i=map1.begin();i!=map1.end();i++){ if (i->second!=map2[i->first]) m=false; } if (m) printf("TRUE\n"); else printf("FALSE\n"); map1.clear(); map2.clear(); } return 0; }