『STA - H1』Code Golf (16bit[v]) 题解
Pursuing_OIer · · 题解
Solution
题目中给出的位比较少,甚至可能只能以四个数字的形式存下整个排列,因此我们考虑直接存储排列使用电路进行复合并判断置换环个数。
考虑从低位到高位依次存储,且
接下来考虑一些性质:对于我们复合得到的置换,假设它是
接下来考虑打表发现
在以上结论上稍加卡常可以只用
- 将原置换中每个数存为
4 位而非2 位可以避免在取出置换2 中的数时进行额外的左移。 - 考虑特判
3 个置换环个数为2 的置换时,因为他们和另一个有4 个置换环的置换形式类似,所以一起判断并在最后加以特判,这样比单独判那3 个置换要少几步。
如此即可通过本题。接下来附上一份 std 以供参考。
#include <bits/stdc++.h>
using namespace std;
using llt = long long;
using llf = long double;
using ull = unsigned long long;
#define endl '\n'
int aas = 0;
int main(){
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
vector<int> p(4); iota(p.begin(), p.end(), 0);
do{
int r = 0, j = 4;
for(auto k : p) r += k * j, j <<= 4;
cout << r << endl;
}while(next_permutation(p.begin(), p.end()));
cout << "49" << endl;
cout << "9 AND 2 N 15" << endl, ++aas;
cout << "4 RSH 1 9" << endl, ++aas;
cout << "4 AND 4 N 15" << endl, ++aas;
cout << "9 RSH 2 N 4" << endl, ++aas;
cout << "9 AND 9 N 15" << endl, ++aas;
cout << "5 RSH 1 9" << endl, ++aas;
cout << "5 AND 5 N 15" << endl, ++aas;
cout << "9 RSH 2 N 8" << endl, ++aas;
cout << "9 AND 9 N 15" << endl, ++aas;
cout << "6 RSH 1 9" << endl, ++aas;
cout << "6 AND 6 N 15" << endl, ++aas;
cout << "9 RSH 2 N 12" << endl, ++aas;
cout << "9 AND 9 N 15" << endl, ++aas;
cout << "7 RSH 1 9" << endl, ++aas;
cout << "7 AND 7 N 15" << endl, ++aas; // get new
cout << "8 RSH N 1 4" << endl, ++aas;
cout << "9 RSH N 32 5" << endl, ++aas;
cout << "8 OR 8 9" << endl, ++aas;
cout << "9 RSH N 1024 6" << endl, ++aas;
cout << "8 OR 8 9" << endl, ++aas;
cout << "9 RSH N 32768 7" << endl, ++aas;
cout << "8 OR 8 9" << endl, ++aas;
cout << "8 AND N 15 8" << endl, ++aas;
cout << "8 POPCNT 8" << endl, ++aas; // get cnt
cout << "3 AND 8 N 4" << endl, ++aas;
cout << "9 AND 8 N 2" << endl, ++aas;
cout << "1 RSH 9 N 1" << endl, ++aas;
cout << "9 OR 9 1" << endl, ++aas;
cout << "3 OR 3 9" << endl, ++aas;
cout << "9 AND 8 N 1" << endl, ++aas;
cout << "9 LSH 9 N 1" << endl, ++aas;
cout << "3 OR 3 9" << endl, ++aas; // normal check
cout << "5 LSH 5 N 4" << endl, ++aas;
cout << "6 LSH 6 N 8" << endl, ++aas;
cout << "7 LSH 7 N 12" << endl, ++aas;
cout << "4 OR 4 5" << endl, ++aas;
cout << "4 OR 4 6" << endl, ++aas;
cout << "4 OR 4 7" << endl, ++aas;
cout << "9 RSH 4 N 4" << endl, ++aas;
cout << "11 AND 9 N 2056" << endl, ++aas;
cout << "11 AND 11 4" << endl, ++aas;
cout << "10 POPCNT 11" << endl, ++aas;
cout << "11 RSH 4 N 8" << endl, ++aas;
cout << "11 AND 11 4" << endl, ++aas;
cout << "11 POPCNT 11" << endl, ++aas;
cout << "10 AND 10 11" << endl, ++aas; // special judge
cout << "8 RSH N 1 8" << endl, ++aas;
cout << "8 LSH 8 10" << endl, ++aas;
cout << "3 OR 3 8" << endl, ++aas; // merge ans
cerr << aas << endl;
}