#include using namespace std; // w[i,j,k] = 1 iff element j of subgrid i has value k // // Relationship between p and subgrid # and element # // // 0 1 2 // __________________________________ // | 0, 1, 2 | 3, 4, 5 | 6, 7, 8 | // 0 | 9,10,11 | 12,13,14 | 15,16,17 | // | 18,19,20 | 21,22,23 | 24,25,26 | // |__________|__________|__________| // | 27,28,29 | 30,31,32 | 33,34,35 | // 1 | 36,37,38 | 39,40,41 | 42,43,44 | // | 45,46,47 | 48,49,50 | 51,52,53 | // |__________|__________|__________| // | 54,55,56 | 57,58,59 | 60,61,62 | // 2 | 63,64,65 | 66,67,68 | 69,70,71 | // | 72,73,74 | 75,76,77 | 78,79,80 | // |__________|__________|__________| // // subgrid row = p/27 // subgrid column = (p/3)%3 // subgrid number = (subgrid row)*3 + subgrid column = (p/27)*3 + (p/3)%3 // element number = 1st row of blocks: (p/9)*3 + p%3 // other rows of blocks: ((p%27)/9)*3 + p%3 int main () { int val, nconstraints = 10287; int var_idx[81]; int count = 0; for (int p=0 ; p < 81 ; p++) { cin >> val; if (val != 0) { int r = p/27, c = ((p/3)%3); var_idx[count++] = 81*(3*r+c) + 9*(((p%27)/9)*3 + p%3) + val; } } nconstraints += count; cout << "p cnf 729 " << nconstraints << "\n"; cout.flush(); system("cat sudoku.cnf"); cout.flush(); for (int i=0 ; i < count ; i++) cout << var_idx[i] << " 0\n"; }