1008 - continue; box[o].cnt--; reset(p+1); if (search(p+1))...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> #include <cstdio> #include <cstdlib> enum { SIZ = 5, UP = 0, RT = 1, DN = 2, LT = 3, MD = 4, }; struct Box{ int val[MD]; int cnt; return (val[UP] == b.val[DN]); } return (val[LT] == b.val[RT]); } return (val[0]==b.val[0]) && (val[1]==b.val[1]) & (val[2]==b.val[2]) && (val[3]==b.val[3]); } }; Box box[28]; int mat[SIZ][SIZ]; int num, edge, size; inline void reset(int p){ int y = p % edge; int x = p / edge; mat[x][y] = -1; } bool search(int p){ if (p>=size) return true; int y = p % edge; int x = p / edge; int &o = mat[x][y]; while(o < num){ ++o; if (box[o].cnt<=0) continue; continue;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: continue; box[o].cnt--; reset(p+1); if (search(p+1)) return true; box[o].cnt++; } return false; } bool fun(){ reset(0); return search(0); } int main(){ int tstcase = 0,i; const char *ans[2] = {&amp;quot;Impossible&amp;quot;, &amp;quot;Possible&amp;quot;}; scanf(&amp;quot;%d&amp;quot;, &amp;amp;num); while(num){ edge = num; size = num * num; num = 0; int j; for(i=0;i&amp;lt;size;i++){ for (j=0; j&amp;lt;MD; j++){ scanf(&amp;quot;%d &amp;quot;, &amp;amp;box[num].val[j]); } box[num].cnt = 1; for (j=0; j&amp;lt;num; j++){ if (box[num].equal(box[j])){ box[j].cnt ++; break; } } num += (j==num); } if(tstcase ++){ printf(&amp;quot;\n&amp;quot;); } printf(&amp;quot;Game %d: &amp;quot;,tstcase); printf(&amp;quot;%s\n&amp;quot;, ans[fun()]); scanf(&amp;quot;%d&amp;quot;, &amp;amp;num); } return 0; }...
View Full Document

Page1 / 2

1008 - continue; box[o].cnt--; reset(p+1); if (search(p+1))...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online