int deepl(int x, int y, int color) { //int count = 0;printf("\033[2J"); int a=0, b=0, c=0, d=0; int max = a; int count = 0; a = deep(x, y, 0, color); b = deep(x, y, 1, color); c = deep(x, y, 2, color); d = deep(x, y, 3, color); max = a; #ifdef DEBUG printf("x=%d;y=%d;a=%d;b=%d;c=%d;d=%d;", x, y, a, b, c, d ); #endif if ((b%10) > (max%10)) max = b; if ((c%10) > (max%10)) max = c; if ((d%10) > (max%10)) max = d; #ifdef DEBUG //if (x<4) printf("之后是x=%d;y=%d;a=%d;b=%d;c=%d;d=%d;max=%d;\n", x, y, a, b, c, d, max ); #endif if (max%10 == 3) { if (a == 13) count=count+10; else if (b==13) count=count+10; else if (c==13) count=count+10; else if (d==13) count=count+10; max = count + 3; } if ((max%10)>=5&&color==go[x][y]&&color!=0) { if (max>10&&((max%10)-1)<5) ; else if (color==1) { printf("\033[2J"); showGo(go); printf("你赢了\n"); exit(0); } else if (color == 2) { printf("\033[2J"); showGo(go); printf("你输了\n"); exit(0); } } return max; }
void solveSudoku(char** board, int boardRowSize, int boardColSize) { //获取全部需要填的字列表 int hash[20]; for (int i = 0;i < boardColSize;i++) { for (int j = 0;j < 10;j++) { hash[j] = 0; } for (int j = 0;j < boardRowSize; j++) { if (board[j][i] != '.') { hash[board[j][i] - '0'] = 1; } } cnt[i] = 0; //stack[i][cnt[i]++] = j + '0'; for (int j = 1;j <= 9;j++) { if (hash[j] == 0) { stack[i][cnt[i]++] = j + '0'; } } } if (deep(board, -1, boardRowSize, boardRowSize, boardColSize) ){ printf("yes\n"); } else { printf("no\n"); } //printf("%s\n", board[0]); }
bool deep(char** board , int lastx, int lasty , int rowSize, int colSize) { if (lasty >= rowSize) { lastx ++; lasty = 0; } for(int i = lastx; i < colSize;i++) { for (int j = lasty;j < rowSize;j++) { if (board[j][i] == '.') { //如果遇到一个需要填的 for (int k = cnt[i] - 1;k >= 0;k--) { // -1 表示已经被使用了 if (stack[i][k] != -1 && check(board, j, i, stack[i][k])) { int old = stack[i][k]; stack[i][k] = -1; board[j][i] = old; printf("board %c\n", board[i][j]); if (deep(board,i,j + 1, rowSize, colSize)) { return true; } printf("board %c\n", board[i][j]); //printf("board %s\n", board[i]); //失败后恢复现场,尝试下一个 stack[i][k] = old; board[i][j] = '.'; } } //但是可选项里面没有找到需要的,该位置不能满足 return false; } } lasty = 0; } //没有遇到一个.表示全部填满了 return true; }
int main() { int n, i, L, R, A[10] = {0}, W = 0; tree T[16]; scanf("%d", &n); for (i = 0; i < n; i++) { T[i].data = i + 1; scanf("%d%d", &L, &R); if (L != 0) { T[i].Lch = &T[L - 1]; } else { T[i].Lch = NULL; } if (R != 0) { T[i].Rch = &T[R - 1]; } else { T[i].Rch = NULL; } } wight(&T[0], A, 0); for (i = 0; i < 10; i++) { // printf("第%d层 %d\n", i + 1, A[i]); if (W < A[i]) W = A[i]; } printf("%d %d\n", W, deep(&T[0])); return 0; }
bool ImageBuf::write (ImageOutput *out, ProgressCallback progress_callback, void *progress_callback_data) const { stride_t as = AutoStride; bool ok = true; if (m_localpixels) { // In-core pixel buffer for the whole image ok = out->write_image (m_spec.format, m_localpixels, as, as, as, progress_callback, progress_callback_data); } else if (deep()) { // Deep image record ok = out->write_deep_image (m_deepdata); } else { // Backed by ImageCache std::vector<char> tmp (m_spec.image_bytes()); get_pixels (xbegin(), xend(), ybegin(), yend(), zbegin(), zend(), m_spec.format, &tmp[0]); ok = out->write_image (m_spec.format, &tmp[0], as, as, as, progress_callback, progress_callback_data); // FIXME -- not good for huge images. Instead, we should read // little bits at a time (scanline or tile blocks). } if (! ok) error ("%s", out->geterror ()); return ok; }
int main() { int v = 3; deep( data, s, v ); printf("\n.................,,,,,,,,\n"); ground( data, s , v ); printf("\n.................,,,,,,,,\n"); }
int ImageBuf::deep_samples (int x, int y, int z) const { if (! deep()) return 0; if (x < m_spec.x || y < m_spec.y || z < m_spec.z) return 0; x -= m_spec.x; y -= m_spec.y; z -= m_spec.z; if (x >= m_spec.width || y >= m_spec.height || z >= m_spec.depth) return 0; int p = (z * m_spec.height + y) * m_spec.width + x; return m_deepdata.nsamples[p]; }
const void * ImageBuf::deep_pixel_ptr (int x, int y, int z, int c) const { if (! deep()) return NULL; if (x < m_spec.x || y < m_spec.y || z < m_spec.z) return NULL; x -= m_spec.x; y -= m_spec.y; z -= m_spec.z; if (x >= m_spec.width || y >= m_spec.height || z >= m_spec.depth || c < 0 || c >= m_spec.nchannels) return NULL; int p = (z * m_spec.height + y) * m_spec.width + x; return m_deepdata.nsamples[p] ? m_deepdata.pointers[p*m_spec.nchannels] : NULL; }
void deep(int data[], int s[][4], int v) { int u; if (1 == vistor[v]) return; printf("%c ", data[v]); vistor[v] = 1; u = get_first_neighbour(s,v); while (-1 != u) { deep(data, s, u); u = get_next_neighbour(s, v, u); } return; }
int bfs( int n, int m ) { int i,j; int ship = 0; memset(touch,false,sizeof(touch)); for( i = 0; i < n; i++ ) for( j = 0; j < m; j++ ) { if( field[i][j] == '#' && touch[i][j] != true ) { if( deep(i,j,n,m) != true ) return -1; ship += 1; } } return ship; }
float ImageBuf::deep_value (int x, int y, int z, int c, int s) const { if (! deep()) return 0.0f; if (x < m_spec.x || y < m_spec.y || z < m_spec.z) return 0.0f; x -= m_spec.x; y -= m_spec.y; z -= m_spec.z; if (x >= m_spec.width || y >= m_spec.height || z >= m_spec.depth || c < 0 || c >= m_spec.nchannels) return 0.0f; int p = (z * m_spec.height + y) * m_spec.width + x; int nsamps = m_deepdata.nsamples[p]; if (s >= nsamps) return 0.0f; const void *ptr = m_deepdata.pointers[p*m_spec.nchannels+c]; TypeDesc t = m_spec.channelformat(c); switch (t.basetype) { case TypeDesc::FLOAT : return ((const float *)ptr)[s]; case TypeDesc::HALF : return ((const half *)ptr)[s]; case TypeDesc::UINT8 : return ConstDataArrayProxy<unsigned char,float>((const unsigned char *)ptr)[s]; case TypeDesc::INT8 : return ConstDataArrayProxy<char,float>((const char *)ptr)[s]; case TypeDesc::UINT16: return ConstDataArrayProxy<unsigned short,float>((const unsigned short *)ptr)[s]; case TypeDesc::INT16 : return ConstDataArrayProxy<short,float>((const short *)ptr)[s]; case TypeDesc::UINT : return ConstDataArrayProxy<unsigned int,float>((const unsigned int *)ptr)[s]; case TypeDesc::INT : return ConstDataArrayProxy<int,float>((const int *)ptr)[s]; case TypeDesc::UINT64: return ConstDataArrayProxy<unsigned long long,float>((const unsigned long long *)ptr)[s]; case TypeDesc::INT64 : return ConstDataArrayProxy<long long,float>((const long long *)ptr)[s]; default: ASSERT (0); return 0.0f; } }
int main(){ std::fstream data; IO::gotoLevel(USER, PASSWORD, 0); data.open("/home/fettpet/ausgDeepSearch.html", std::ios::out); data << "<html><body><table border=\"1\">" << std::endl; data << "<tr><th>Level</th><th>Size</th><th>Tiles</th><th>Modulo</th><th>Time</th></tr>" << std::endl; for(uint lev = 0; lev < 62; ++lev){ bool solved(false); boost::timer timer; Solver::TabuSearch::setNewGame(); Game::Game gameField(IO::readGameFromHackerOrg(USER, PASSWORD)); std::cout << gameField << std::endl; Solver::DeepSearch deep(gameField); Game::Game solution = deep.getSolution(); data << "<tr><th>" << lev << "</th><th>(" << gameField.getField().getSizeX() << ", " << gameField.getField().getSizeY() << ")</th><th>" << gameField.getTileCount() << "</th><th>" << (int)solution.getField().getMod() << "</th><th>" << timer.elapsed() << "</th></tr>" << std::endl; IO::writeSolutionToHacker(USER, PASSWORD, solution.getHackerOrgSolution()); } }
int shallow ( int x ) { return deep(x + 3); }
int deep(tree *T) { if (T) { return deep(T->Lch) > deep(T->Rch) ? deep(T->Lch) + 1 : deep(T->Rch) + 1; } else return 0; }
/*绘制*/ void CheckersPicture::paintEvent(QPaintEvent *event) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing, true); painter.setViewport(p.x(),p.y(),side,side); painter.setWindow(0, 0, zoom*(n), zoom*(n)); QColor dark(0xcc,0xcc,0xcc,200); QColor endColor(0x78,0xff,0x21,200); /*终点颜色*/ QColor startColor(0xea,0x76,0x0f,200); /*起点颜色*/ QColor capturedColor(0xed,0x50,0x62,200); /*捕获颜色*/ QColor normalColor(0xd6,0xb8,0x2c,200); /*正常色*/ QColor black(0x00, 0x00, 0x00, 200); QColor white(0xff, 0xff, 0xff, 220); QColor light(0xed,0xfc,0xdf,200); QColor deep(0x5a,0x61,0x54,200); /*绘制棋盘*/ for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { QRect rect = pixelRect(i, j); if( !((i+j%2)%2) ) { painter.fillRect(rect, deep); } else { painter.fillRect(rect, light); } } } int ix,jx; if(v.size()) { int type; for(unsigned i=0; i< v.size(); i++) { color==WHITE ? jx = n-1-v.at(i).y : jx = v.at(i).y; color==WHITE ? ix = n-1-v.at(i).x : ix = v.at(i).x; QRect rect = pixelRect(ix, jx); type = v.at(i).type; if(type == MOVEDFROM) painter.fillRect(rect, startColor); else if(type == MOVEDTO || type == TOKING) painter.fillRect(rect, endColor); else if(type == MOVEDTHROUGH) painter.fillRect(rect, normalColor); else if(type == DELETED) painter.fillRect(rect, capturedColor); } } int s = zoom*0.4; int sd = zoom*0.3; /*画白棋*/ if(curstate){ /*如果棋局状态发生了改变*/ painter.setPen(QPen(black,zoom*0.025)); painter.setBrush(QBrush(white)); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { /*如果是白色则从最后一行开始画*/ color==WHITE ? jx = j+1 : jx = n-j; color==WHITE? ix = n-i : ix = i+1; if(curstate->at(i,j)==WHITE) painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); if(curstate->at(i,j)==WHITEKING) { painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),sd,sd); } } } /*画黑棋*/ painter.setBrush(QBrush(black)); for(int i=0; i<n; i++) { for(int j=0; j<n; j++) { color==WHITE ? jx = j+1 : jx = n-j; color==WHITE ? ix = n-i : ix = i+1; if(curstate->at(i,j)==BLACK) painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); if(curstate->at(i,j)==BLACKKING) { painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),s,s); painter.setPen(QPen(white,zoom*0.1)); painter.drawEllipse(QPoint(zoom*(ix-0.5),zoom*(jx-0.5)),sd,sd); painter.setPen(QPen(black,zoom*0.1)); } } } } if (thinking && showHourglass) { painter.setWindow(painter.viewport()); painter.drawImage((width() - hourglass.width()) / 2, (height() - hourglass.height()) / 2, hourglass); } }