Advertisement
Guest User

Untitled

a guest
Jun 14th, 2011
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.05 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define N(I,l) s l]=(I?1<<I|I<<10:01776)
  5. #define f(a,t) for(a=0;a<t;a++)
  6. #define Su(d,o,ku) O(l/9,d) O(l%9,o) O(l%9/3+l/27*3,ku)
  7. #define NO ;printf("%c %s",I?I|48:46,++l%3?"":l%9?"| ":l%27?"\n":l%'Q'?z:"\n");
  8. #define Ba(k,a) {O||printf("!!! " #a " %i\n",k+1);goto l;}
  9. #define O(o,k) f(l,9) c[l]= *#k?0x3fe:-1;\
  10.   f(l,81) if(*#k){\
  11.     if(!(s]&c[o])) Ba(o,k) c[o]&=~(1<<(s]>>10));\
  12.   } else if((s]>>l0)&1) c[o]=c[o]+1?-2:l;\
  13.   if(*#k) { f(l,81) if(s]>>10||(s]&=c[o]),!s]) Ba(o,k) }\
  14.   else f(l,9) l[c]<0||s[c]]>>10||(N(l0,[c]),C++);
  15.  
  16. struct{ int s[81],I,l,O; } S[0123];
  17. int I, l, l0, o, C, O=0, w=0, c[10], L; long i;
  18. char z[] = "\007      &       &      \n";
  19.  
  20. #define s S].s[l
  21.  
  22. int main(int n,char**N) {
  23.     S->O=0; L=n>1?*N[1]-85?1:6:0; i=L&1?atol(N[1]):123;
  24. #define i (int)(81.0*(i=1103515245*i+12345&0x7fffffff)/2147483648.0)
  25.     for(l=C=0;l<81;) {
  26.     I=L&1?0:getchar()^48; i; I=I-30?I:0;
  27.     if(I<10) {
  28.         #define S S[O
  29.         if(C<22) z[C++]^=13; N(I,)NO
  30.     }
  31.     }
  32.  
  33.     for(;;) {
  34.     l0:
  35.         Su(row,col,box) C=l0=0;
  36.     f(l,81) if(!(s]>>10&&++l0)) {
  37.       o=s]&1022; for(I=0;~o&1&&(o/=2);I++); o-1||(s]|=I<<10,C++);
  38.     } if(l0==l) {
  39.       if(O&&L&2) { O--; goto l0; } goto O;
  40.     } for(l0=1;10>l0;l0++) { Su(,,) }
  41.  
  42.     if(!C) {
  43.         l=(o=S].O)?S].I:0; I=o?S].l%9+1:(S].O=i%9+1);
  44.         for(;l<81;l++,I=S].O,o=0) if(!(s]>>10)) {
  45.         for(;;I=I%9+1,o=1) {
  46.             l0=0; if(o&&I==S].O) goto O;
  47.             if(s]>>I&1) {
  48.             S].l=I; S++].I=l; S]=S-1];
  49.             N(I,); O>w&&(w=O); goto lO;
  50.             }
  51.         }
  52.         }
  53.     }
  54.     lO: S].O=0; goto l0; l: if(!(l0=O)) { L=0; goto O; } O--;
  55.     s,S].I] &=~ (1<<S].l);
  56.     }
  57.  
  58.     O: switch(L) {
  59.     case 2: if(l0) {
  60.     case 3: O=82;
  61.         for(S].l=l=i%81;l0||S].l-l;l=(l+1)%81)
  62.              O1: if(l0=0,S].O=s]>>10,~s]&1) {
  63.         s]=1023; S].I=l; S&0]=S]; w=O=0; L=2; goto lO;
  64.         }
  65.         L=0; l0=1;
  66.     } else {
  67.         l=S=82].I; N(S].O,)|1; goto O1;
  68.     }
  69.     }
  70.  
  71.     printf("\n\n"); for(l=0;l<81;) {I=s]>>10 NO}
  72.     printf("\n%s (stk %i %i)\n",l0?"Done":"No way!",O,w);
  73.     L|=2; if(L-3||!l0) return!l0; S,82]=S]; goto O;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement