hdu6708 Windows Of CCPC
传送门
第一次看到这个题感觉非常高大上,又过了几个月,我又碰见了。发现是一个水题。直接用三维字符数组模拟可以,但是我感觉略微麻烦,我想到了用string,比用三维字符数组更方便。话不多说,代码如下。`
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
const int maxn = 2e6 + 7;
typedef long long ll;
using namespace std;
const ll mod = 10007;
const long double pi = 3.1415926535897932384626433832795;
priority_queue<int, vector<int>, greater<int> > q;
string mp[12][1024];
string pm[12][1024];
int main(){
mp[1][0] = "CC";
mp[1][1] = "PC";
pm[1][0] = "PP";
pm[1][1] = "CP";
for (int i = 2; i <= 10; i ++){
int j = 0;
for (int k = 0; k < pow(2,i - 1); k ++){
mp[i][j++] = mp[i-1][k] + mp[i-1][k];
}
for (int k = 0; k < pow(2,i-1); k ++){
mp[i][j++] = pm[i-1][k] + mp[i-1][k];
}
j = 0;
for (int k = 0; k < pow(2,i-1); k ++){
pm[i][j++] = pm[i-1][k] + pm[i-1][k];
}
for (int k = 0; k < pow(2,i-1); k ++){
pm[i][j++] = mp[i-1][k] + pm[i-1][k];
}
}
int t, n;
cin >> t;
while (t--){
cin >> n;
for (int i = 0; i < pow(2,n); i ++)
cout << mp[n][i] << endl;
}
return 0;
}
string 的方便之处是他可以进行加法运算,不用注意下标的问题。