Sigils of Elohim

题目大意

  见游戏链接https://store.steampowered.com/app/321480/

分析

  作为一个程序猿,我拒绝用人脑dfs。

代码如下

  1 #include <bits/stdc++.h>
  2 using namespace std;
  3  
  4 #define INIT() ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  5 #define Rep(i,n) for (int i = 0; i < (n); ++i)
  6 #define For(i,s,t) for (int i = (s); i <= (t); ++i)
  7 #define rFor(i,t,s) for (int i = (t); i >= (s); --i)
  8 #define ForLL(i, s, t) for (LL i = LL(s); i <= LL(t); ++i)
  9 #define rForLL(i, t, s) for (LL i = LL(t); i >= LL(s); --i)
 10 #define foreach(i,c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
 11 #define rforeach(i,c) for (__typeof(c.rbegin()) i = c.rbegin(); i != c.rend(); ++i)
 12  
 13 #define pr(x) cout << #x << " = " << x << "  "
 14 #define prln(x) cout << #x << " = " << x << endl
 15  
 16 #define LOWBIT(x) ((x)&(-x))
 17  
 18 #define ALL(x) x.begin(),x.end()
 19 #define INS(x) inserter(x,x.begin())
 20 #define UNIQUE(x) x.erase(unique(x.begin(), x.end()), x.end())
 21 #define REMOVE(x, c) x.erase(remove(x.begin(), x.end(), c), x.end()); // 删去 x 中所有 c 
 22 #define TOLOWER(x) transform(x.begin(), x.end(), x.begin(),::tolower);
 23 #define TOUPPER(x) transform(x.begin(), x.end(), x.begin(),::toupper);
 24  
 25 #define ms0(a) memset(a,0,sizeof(a))
 26 #define msI(a) memset(a,0x7f,sizeof(a))
 27 #define msM(a) memset(a,-1,sizeof(a))
 28 
 29 #define MP make_pair
 30 #define PB push_back
 31 #define ft first
 32 #define sd second
 33  
 34 template<typename T1, typename T2>
 35 istream &operator>>(istream &in, pair<T1, T2> &p) {
 36     in >> p.first >> p.second;
 37     return in;
 38 }
 39  
 40 template<typename T>
 41 istream &operator>>(istream &in, vector<T> &v) {
 42     for (auto &x: v)
 43         in >> x;
 44     return in;
 45 }
 46 
 47 template<typename T>
 48 ostream &operator<<(ostream &out, vector<T> &v) {
 49     Rep(i, v.size()) out << v[i] << " 
"[i == v.size()];
 50     return out;
 51 }
 52  
 53 template<typename T1, typename T2>
 54 ostream &operator<<(ostream &out, const std::pair<T1, T2> &p) {
 55     out << "[" << p.first << ", " << p.second << "]" << "
";
 56     return out;
 57 }
 58 
 59 inline int gc(){
 60     static const int BUF = 1e7;
 61     static char buf[BUF], *bg = buf + BUF, *ed = bg;
 62     
 63     if(bg == ed) fread(bg = buf, 1, BUF, stdin);
 64     return *bg++;
 65 } 
 66 
 67 inline int ri(){
 68     int x = 0, f = 1, c = gc();
 69     for(; c<48||c>57; f = c=='-'?-1:f, c=gc());
 70     for(; c>47&&c<58; x = x*10 + c - 48, c=gc());
 71     return x*f;
 72 }
 73 
 74 template<class T>
 75 inline string toString(T x) {
 76     ostringstream sout;
 77     sout << x;
 78     return sout.str();
 79 }
 80 
 81 inline int toInt(string s) {
 82     int v;
 83     istringstream sin(s);
 84     sin >> v;
 85     return v;
 86 }
 87 
 88 //min <= aim <= max
 89 template<typename T>
 90 inline bool BETWEEN(const T aim, const T min, const T max) {
 91     return min <= aim && aim <= max;
 92 }
 93  
 94 typedef long long LL;
 95 typedef unsigned long long uLL;
 96 typedef pair< double, double > PDD;
 97 typedef pair< int, int > PII;
 98 typedef pair< int, PII > PIPII;
 99 typedef pair< string, int > PSI;
100 typedef pair< int, PSI > PIPSI;
101 typedef set< int > SI;
102 typedef set< PII > SPII;
103 typedef vector< int > VI;
104 typedef vector< double > VD;
105 typedef vector< VI > VVI;
106 typedef vector< SI > VSI;
107 typedef vector< PII > VPII;
108 typedef map< int, int > MII;
109 typedef map< int, string > MIS;
110 typedef map< int, PII > MIPII;
111 typedef map< PII, int > MPIII;
112 typedef map< string, int > MSI;
113 typedef map< string, string > MSS;
114 typedef map< PII, string > MPIIS;
115 typedef map< PII, PII > MPIIPII;
116 typedef multimap< int, int > MMII;
117 typedef multimap< string, int > MMSI;
118 //typedef unordered_map< int, int > uMII;
119 typedef pair< LL, LL > PLL;
120 typedef vector< LL > VL;
121 typedef vector< VL > VVL;
122 typedef priority_queue< int > PQIMax;
123 typedef priority_queue< int, VI, greater< int > > PQIMin;
124 const double EPS = 1e-8;
125 const LL inf = 0x7fffffff;
126 const LL infLL = 0x7fffffffffffffffLL;
127 const LL mod = 1e9 + 7;
128 const int maxN = 1e5 + 7;
129 const LL ONE = 1;
130 const LL evenBits = 0xaaaaaaaaaaaaaaaa;
131 const LL oddBits = 0x5555555555555555;
132 
133 struct Point{
134     int X, Y; 
135     
136     Point() {}
137     Point(int x, int y) : X(x), Y(y) {}
138     
139     Point operator+ (const Point &x) const {
140         Point ret;
141         ret.X = X + x.X;
142         ret.Y = Y + x.Y;
143         return ret;
144     }
145     
146     Point operator- (const Point &x) const {
147         Point ret;
148         ret.X = X - x.X;
149         ret.Y = Y - x.Y;
150         return ret;
151     }
152 };
153 
154 vector< vector< vector< Point > > > type = {
155                             // type #1
156                             // ***
157                             // *
158                             {
159                                 {Point(0, 0), Point(0, 1), Point(0, 2), Point(1, 0)},
160                                 {Point(0, 0), Point(0, 1), Point(1, 1), Point(2, 1)},
161                                 {Point(0, 0), Point(0, 1), Point(0, 2), Point(-1, 2)},
162                                 {Point(0, 0), Point(1, 0), Point(2, 0), Point(2, 1)}
163                             },
164                             // type #2
165                             // ***
166                             //   *
167                             {
168                                 {Point(0, 0), Point(1, 0), Point(1, 1), Point(1, 2)},
169                                 {Point(0, 0), Point(0, 1), Point(1, 0), Point(2, 0)},
170                                 {Point(0, 0), Point(0, 1), Point(0, 2), Point(1, 2)},
171                                 {Point(0, 0), Point(0, 1), Point(-1, 1), Point(-2, 1)}
172                             },
173                             // type #3
174                             //  **
175                             // **
176                             {
177                                 {Point(0, 0), Point(0, 1), Point(-1, 1), Point(-1, 2)},
178                                 {Point(0, 0), Point(1, 0), Point(1, 1), Point(2, 1)}
179                             },
180                             // type #4
181                             // **
182                             //  **
183                             {
184                                 {Point(0, 0), Point(0, 1), Point(1, 1), Point(1, 2)},
185                                 {Point(0, 0), Point(1, 0), Point(0, 1), Point(-1, 1)}
186                             },
187                             // type #5
188                             // ****
189                             {
190                                 {Point(0, 0), Point(0, 1), Point(0, 2), Point(0, 3)},
191                                 {Point(0, 0), Point(1, 0), Point(2, 0), Point(3, 0)}
192                             },
193                             // type #6
194                             // **
195                             // **
196                             {
197                                 {Point(0, 0), Point(0, 1), Point(1, 0), Point(1, 1)}
198                             },
199                             // type #7
200                             //  *
201                             // ***
202                             {
203                                 {Point(0, 0), Point(0, 1), Point(0, 2), Point(-1, 1)},
204                                 {Point(0, 0), Point(1, 0), Point(2, 0), Point(1, 1)},
205                                 {Point(0, 0), Point(0, 1), Point(0, 2), Point(1, 1)},
206                                 {Point(0, 0), Point(0, 1), Point(-1, 1), Point(1, 1)}
207                             }
208                                };
209 
210 int m, n;
211 int board[17][17];
212 MII types;
213 int cnt;
214 
215 void init() {
216     Rep(i, type.size()) {
217         vector< vector< Point > > tmp;
218         Rep(j, type[i].size()) {
219             vector< Point > t;
220             Rep(k, type[i][j].size()) {
221                 if(k == 0) continue;
222                  Rep(h, type[i][j].size()) t.PB(type[i][j][h] - type[i][j][k]);
223                  tmp.PB(t);
224                  t.clear();
225             }
226         }
227         foreach(j, tmp) type[i].PB(*j);
228         tmp.clear();
229     }
230     
231     /*
232     Point s(2, 2);
233     Rep(i, type.size()) {
234         Rep(j, type[i].size()) {
235             int b[6][6];
236             ms0(b);
237             Rep(k, type[i][j].size()) {
238                 Point tmp = s + type[i][j][k];
239                 b[tmp.X][tmp.Y] = i + 1;
240             }
241             
242             For(tx, 0, 5) {
243                 For(ty, 0, 5) cout << b[tx][ty];
244                 cout << endl;
245             }
246             cout << "**************************************
";
247         }
248     }
249     */
250 }
251 
252 bool check(int x, int y, int i, int j) {
253     Point s(x, y);
254     Rep(k, type[i][j].size()) {
255         Point tmp = s + type[i][j][k];
256         if(!BETWEEN(tmp.X, 1, m) || !BETWEEN(tmp.Y, 1, n) || board[tmp.X][tmp.Y]) return false;
257     }
258     return true;
259 }
260 
261 void print(){
262     For(i, 1, m) {
263         For(j, 1, n) cout << board[i][j];
264         cout << endl;
265     }
266     cout << "**************************************
";
267 }
268 
269 inline void dfs(int x, int y) {
270     Point s(x, y);
271     
272     Rep(i, type.size()) {
273         if(!types[i + 1]) continue;
274         Rep(j, type[i].size()) {
275             if(!check(x, y, i, j)) continue;
276             
277             Rep(k, type[i][j].size()) {
278                 Point tmp = s + type[i][j][k];
279                 board[tmp.X][tmp.Y] = i + 1;
280             }
281             --types[i + 1];
282             cnt += 4;
283             
284             if(cnt == m * n) {
285                 print();
286                 return;
287             }
288             
289             For(tx, 1, m) {
290                 For(ty, 1, n) {
291                     if(!board[tx][ty]) {
292                         dfs(tx, ty);
293                         tx = m;
294                         break;
295                     }
296                 }
297             }
298             
299             cnt -= 4;
300             ++types[i + 1];
301             Rep(k, type[i][j].size()) {
302                 Point tmp = s + type[i][j][k];
303                 board[tmp.X][tmp.Y] = 0;
304             }
305         }
306     }
307 }
308 
309 int main(){
310     //freopen("MyOutput.txt","w",stdout);
311     //freopen("input.txt","r",stdin);
312     //INIT();
313     init();
314     
315     cin >> m >> n; // 棋盘规格 
316     For(i, 1, 7) cin >> types[i]; // 每种积木的数量 
317     
318     dfs(1, 1);
319     return 0;
320 }
View Code