int dfs(int x, int y) { if (y == 9) { if (!safe(x-1, y-1) || !safe(x-1, y-2)) return 0; x++, y = 0; } if (x == 9) { for (int i = 0; i < 9; i++) if (!safe(8, i)) return 0; for (int i = 0; i < 9; i++) for (int j = 0; j < 9; j++) printf("%d%c", ret[i][j], j == 8 ? '\n' : ' '); return 1; } if (!safe(x-1, y-2)) return 0; if (dfs(x, y+1)) return 1; int f = canplace(x, y); if (f) { _remove(x, y); if (dfs(x, y+1)) return 1; _resume(x, y); } return 0; }
void Jit::Comp_FPULS(MIPSOpcode op) { CONDITIONAL_DISABLE; s32 offset = _IMM16; int ft = _FT; MIPSGPReg rs = _RS; switch(op >> 26) { case 49: //FI(ft) = Memory::Read_U32(addr); break; //lwc1 { gpr.Lock(rs); fpr.SpillLock(ft); fpr.MapReg(ft, false, true); JitSafeMem safe(this, rs, offset); OpArg src; if (safe.PrepareRead(src, 4)) MOVSS(fpr.RX(ft), src); if (safe.PrepareSlowRead(&Memory::Read_U32)) { MOV(32, M(&ssLoadStoreTemp), R(EAX)); MOVSS(fpr.RX(ft), M(&ssLoadStoreTemp)); } safe.Finish(); gpr.UnlockAll(); fpr.ReleaseSpillLocks(); } break; case 57: //Memory::Write_U32(FI(ft), addr); break; //swc1 { gpr.Lock(rs); fpr.SpillLock(ft); fpr.MapReg(ft, true, false); JitSafeMem safe(this, rs, offset); OpArg dest; if (safe.PrepareWrite(dest, 4)) MOVSS(dest, fpr.RX(ft)); if (safe.PrepareSlowWrite()) { MOVSS(M(&ssLoadStoreTemp), fpr.RX(ft)); safe.DoSlowWrite(&Memory::Write_U32, M(&ssLoadStoreTemp)); } safe.Finish(); gpr.UnlockAll(); fpr.ReleaseSpillLocks(); } break; default: _dbg_assert_msg_(CPU,0,"Trying to interpret FPULS instruction that can't be interpreted"); break; } }
void TActiveScroller::SetScrollBarValue(short value) { #if TARGET_API_MAC_CARBON==1 Rect rect; GetControlBounds(scrollBar,&rect); UClipSaver safe(rect); #else UClipSaver safe((**scrollBar).contrlRect); #endif SetControlValue(scrollBar,value); }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ PaintAll // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Paints the entire canvas with the fore colour void CBLCanvas::PaintAll() { UWorldSaver safe(mWorld); Rect rect; #if TARGET_API_MAC_CARBON ::GetPortBounds(mWorld,&rect); #else rect=mWorld->portRect; #endif ::RGBForeColour(&mForeColour); ZeroRectCorner(rect); #if TARGET_API_MAC_CARBON Pattern pat; ::GetQDGlobalsBlack(&pat); ::FillRect(&rect,&pat); #else ::FillRect(&rect,&qd.black); #endif if (mInvalCanvasAsDraw) InvalCanvasRect(rect); }
int cell_main(int argc, char **argv) { netmsg_p msg; netdev_p nd; int status; msg = malloc(sizeof(struct netmsg)); memset(msg, 0, sizeof(struct netmsg)); nd = netdev_setup(to_pep, from_pep); if (nd == NULL) { printf("Error setting up network client\n"); return 1; } while (1) { if ((status = netdev_recv(nd, msg))) { printf("Error\n"); return 1; } if (safe(msg->payload)) if ((status = netdev_send(nd, msg))) { printf("Error\n"); return 1; } } return 0; }
int main() { int ans=0; int i, j, y, x; scanf("%d%d", &r, &c); for(i=0; i<r; i++) for(j=0; j<c; j++) scanf("%d", &g[i][j]); for(i=0; i<r; i++) { for(j=0; j<c; j++) { for(y=0; y<19; y++) { int tmp = 0; for(x=0; x<4; x++) { int nI = i+di[y][x]; int nJ = j+dj[y][x]; tmp += (safe(nI, nJ) ? g[nI][nJ] : -100000000); } if(ans < tmp) ans = tmp; } } } printf("%d\n", ans); return 0; }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ LoadMusicSelf /*e*/ // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ void CQTMusicDriver::LoadMusicSelf( FSSpec &inSpec) { UPortSaver safe(sWindow); Str255 movieName; Boolean wasChanged; SInt16 movieResFile,movieResID; OSErr err; ThrowIfOSErr_(::OpenMovieFile(&inSpec,&movieResFile,fsRdPerm)); err=::NewMovieFromFile(&mMovie,movieResFile,&movieResID,movieName,newMovieActive,&wasChanged); if (err) { ::CloseMovieFile(movieResFile); ThrowIfOSErr_(err); } ThrowIfOSErr_(::CloseMovieFile(movieResFile)); ::GoToBeginningOfMovie(mMovie); ::SetMovieVolume(mMovie,mVolumeLevel); // apply current volume // if we're supposed to be looping make sure we apply the property to the movie if (mIsLooping) { mIsLooping=false; SetLooping(true); } }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ FramePoly // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ void CBLCanvas::FramePoly( SInt32 *inArray, SInt32 inNumCoOrdPairs) { UWorldSaver safe(mWorld); ::RGBForeColour(&mForeColour); ::RGBBackColour(&mBackColour); ::MoveTo(inArray[0],inArray[1]); if (PolyHandle poly=::OpenPoly()) { for (SInt32 counter=2; counter<inNumCoOrdPairs*2; counter+=2) ::LineTo(inArray[counter],inArray[counter+1]); ::ClosePoly(); ::FramePoly(poly); // Inval the rect if (mInvalCanvasAsDraw) { Rect rect=(*poly)->polyBBox; rect.bottom++; rect.right++; InvalCanvasRect(rect); } ::KillPoly(poly); } }
void nqueens(char *config, int n, int i) { char *new_config; int j; if (i==n) { count++; } /* try each possible position for queen <i> */ for (j=0; j<n; j++) { /* allocate a temporary array and copy the config into it */ new_config = malloc((i+1)*sizeof(char)); memcpy(new_config, config, i*sizeof(char)); if (safe(new_config, i, j)) { new_config[i] = j; nqueens(new_config, n, i+1); } free(new_config); } // sync return; }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ DrawLine // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Draws a line x across and y down void CBLCanvas::DrawLine( SInt16 inX1, SInt16 inY1, SInt16 inX2, SInt16 inY2) { UWorldSaver safe(mWorld); ::RGBForeColour(&mForeColour); ::MoveTo(inX1,inY1); ::LineTo(inX2,inY2); // Inval the rect if (mInvalCanvasAsDraw) { Rect rect; rect.top=inY1; rect.left=inX1; rect.bottom=inY2; rect.right=inX2; // Validate the rect (swap left/right top/bottom so it's in order) ValidateRect(rect); // Extend the rect to capture right and lower pixels rect.bottom++; rect.right++; // Mark it for blitting InvalCanvasRect(rect); } }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ Copy // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ void CBLCanvas::Copy( GWorldPtr inSourceWorld, const Rect &inCopyRect, SInt16 inDestX, SInt16 inDestY) { // Quick check of the params for null copies... if (inDestX>=mABCRec.width || inDestY>=mABCRec.height) return; if (FRectWidth(inCopyRect)==0 || FRectHeight(inCopyRect)==0) return; // Calc the dest rect Rect destRect=inCopyRect,srcRect=inCopyRect; inDestX-=destRect.left; inDestY-=destRect.top; FOffset(destRect,inDestX,inDestY); // And invoke the mighty CopyBits UWorldSaver safe(mWorld); ::RGBForeColour(&TColourPresets::kBlack); ::RGBBackColour(&TColourPresets::kWhite); #if TARGET_API_MAC_CARBON ::CopyBits((BitMap*)*(GetPortPixMap(inSourceWorld)),(BitMap*)*mABCRec.rec.pixMap,&srcRect,&destRect,srcCopy,0L); #else ::CopyBits((BitMap*)*(inSourceWorld->portPixMap),(BitMap*)*mABCRec.rec.pixMap,&srcRect,&destRect,srcCopy,0L); #endif if (mInvalCanvasAsDraw) InvalCanvasRect(destRect); }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ DrawPict // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Draws a pict into the world void CBLCanvas::DrawPict( PicHandle inHandle, const Rect &inRect) { UWorldSaver safe(mWorld); ::DrawPicture(inHandle,&inRect); InvalCanvasRect(inRect); }
int main() { Pointer<Item> item(new Item); item->foo(); item->bar(); Pointer<WithMutex<std::string>> safe(new std::string); safe->empty(); }
void TActiveScroller::IndicatorProc(Point origPoint) { #if TARGET_API_MAC_CARBON==1 UPortSaver safe(GetControlOwner(scrollBar)); #else UPortSaver safe((**scrollBar).contrlOwner); #endif Point lastPoint,currentPoint; short value; short originalValue=GetScrollBarValue(); // While we're tracking the thumb, we're calculating its value based // on the current mouse location. That works great, assuming you // clicked _exactly_ in the center of the thumb. We calculate how // much we need to compensate the value caluculations based on the // click distance from the center of the thumb. valueSlop=0; // Important as the valueSlop is used in the CalcScrollBarValueFromPoint proc valueSlop=originalValue-CalcScrollBarValueFromPoint(origPoint); currentPoint=lastPoint=origPoint; while (StillDown()) { // Only attempt to update the value if the mouse moved. GetMouse(¤tPoint); if (EqualPt(currentPoint,lastPoint)) continue; // Remeber where the last mouse location was lastPoint=currentPoint; // Check to see if the user tracked outside of the slop rect. // If they did, restore the original value of the control. // This mimics the same behaviour as the standard scroll bar. if (FPointInRect(currentPoint,trackRect)) value=CalcScrollBarValueFromPoint(currentPoint); else value=originalValue; value=Limit(value,::GetControlMinimum(scrollBar),::GetControlMaximum(scrollBar)); SetScrollBarValue(value); } }
Boolean TActiveScroller::HandleMouseClick(Point inPoint) { #if TARGET_API_MAC_CARBON==1 UPortSaver safe(GetControlOwner(scrollBar)); #else UPortSaver safe((**scrollBar).contrlOwner); #endif short partCode; if (partCode=TestControl(scrollBar,inPoint)) { switch (partCode) { case kControlUpButtonPart: case kControlDownButtonPart: case kControlPageDownPart: case kControlPageUpPart: case kControlIndicatorPart: SetupScroll(); if (partCode==kControlIndicatorPart) { // Dim the thumb HiliteControl(scrollBar,kControlIndicatorPart); IndicatorProc(inPoint); // Undim the thumb HiliteControl(scrollBar,kControlNoPart); } else { // Must call this to pass the current object to the tracking proc SetTrackingObject(this); TrackControl(scrollBar,inPoint,scrollBarProcUPP); } ShutdownScroll(); return true; break; } } return false; // missed the scroll bar }
void SoftMatching::propagate_21 () { total_2(); for (size_t ij = 0; ij < size_arc(); ++ij) { Arc arc = m_arcs[ij]; float projected = likelihood_ratio(m_post_2_ass[ij], m_total[arc.j]); m_message[ij] = safe(projected / (m_message[ij] * m_prior_2_ass[ij])); m_prior_2_ass[ij] = projected; float lifted = m_message[ij] * m_scale_1[arc.i]; m_post_1_ass[ij] = safe(m_post_1_ass[ij] * lifted); ASSERT1_PROB(m_message[ij]); ASSERT1_PROB(m_prior_2_ass[ij]); ASSERT1_PROB(m_post_1_ass[ij]); } }
void Monster::go_safe_place(std::deque<AObject*> &map) { unsigned int i = 0; bool is_safe = false; int left = 1, right = 1, up = 1, down = 1; while (is_safe == false && i < map.size()) { if ((map[i]->getType() == DANGER || map[i]->getType() == BOMB) && map[i]->getPosition().x + 160 >= position_.x && map[i]->getPosition().x - 160 <= position_.x && map[i]->getPosition().z + 160 >= position_.z && map[i]->getPosition().z - 160 <= position_.z) { if ((safe(position_.x + (300 * i), position_.z, map, &left) == true) || (safe(position_.x - (300 * i), position_.z, map, &right) == true)) { if (left == 1) { go_left(map, 0); is_safe = true; } else if (right == 1) { go_right(map, 0); is_safe = true; } } else { if (up == 1) { go_up(map, 0); is_safe = true; } else if (down == 1) { go_down(map, 0); is_safe = true; } } i++; } i++; } }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ SetPixelRGB // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Ignores attempts to set outside of bounds void CBLCanvas::SetPixelRGB( SInt16 inX, SInt16 inY, const RGBColour &inColour) { if (inX<0 || inY<0 || inX>=GetWidth() || inY>=GetHeight()) return; UWorldSaver safe(mWorld); ::SetCPixel(inX,inY,&inColour); }
/*--------------------进行广度搜索查找解-------------------------*/ void BFS(Link *p,int n,int c) { Link *q,*t; DataType tem; int i,flag1,flag2,g=0,j; int count=0; //标记解的个数 q=p->son; while (q!=NULL) { flag1=0; j=boatcase(q->data,c);//可能过河的情况 for (i=0;i<j;i++)//搜索兄弟结点 { tem.husb=q->data.husb-array[i].husb; tem.wife=q->data.wife-array[i].wife; tem.cw=1-q->data.cw; t=q; if (safe(tem,n))//是否安全 { flag2=1;//1表示没有死循环 while (t!=p)//保证不会出现循环 { if(tem.husb== t->data.husb&&tem.wife==t->data.wife&&tem.cw==t->data.cw) {//出现相当情况时候 flag2=0; break; } t=t->par; } if(flag2==1) { if (flag1==0) { insertson(q, tem); flag1=1; } else insertbro(q,tem); if (tem.husb==0&&tem.wife==0&&tem.cw==0) //当检测到这个状态时,说明问题得到正确解 { print(q,p); count++; } } } } q=q->next; } if (count==0) printf("无法成功渡河!\n"); else printf("有%d种渡河方式。\n",count); }
void queen_cols(int k, int board_size) { // k for col for (int row = 1; row <= board_size; row++) { if (safe(k, row)) { row_positions[k] = row; if (k == board_size) { handle_found_solution(board_size); } else { queen_cols(k+1, board_size); } } } }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ FrameOval // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Draws a hollow oval void CBLCanvas::FrameOval( const Rect &inRect) { UWorldSaver safe(mWorld); ::RGBForeColour(&mForeColour); ::RGBBackColour(&mBackColour); ::FrameOval(&inRect); // Inval the rect if (mInvalCanvasAsDraw) InvalCanvasRect(inRect); }
void scan(int n) { if (n == 13) { solutions++; return; } int pos; for (pos = 0; pos < 13; pos++) { queens[n] = pos; if (safe(n)) scan(n + 1); } }
int main(void) { /* clear terminal screen */ system("/usr/bin/clear"); /* initialize system state from user input */ init_state(); /* notify user of status and wait for "O.K." to run the system */ while (getchar() != '\n'); printf("System initialized. To \"run\" the system, press ENTER."); getchar(); /* main program loop */ while (1) { /* clear screen */ system("/usr/bin/clear"); /* allocate resources and display */ allocate_random(); display_allocation(); putchar('\n'); display_need(); putchar('\n'); display_available(); putchar('\n'); /* display result of "safe()" */ if (safe()) printf("System state: SAFE!\n"); else printf("System state: UNSAFE!\n"); /* prompt user to continue or quit */ putchar('\n'); printf("Press Ctrl-C to quit. To \"run\" again, press ENTER."); getchar(); /* if continue, restore the system */ restore(); } /* free dynamically allocated memory, unnecessary here unless user interface is altered to allow the code to reach this point */ vector_destroy(AVAILABLE); matrix_destroy(MAX, NUMBER_OF_PROCESSES); matrix_destroy(ALLOCATION, NUMBER_OF_PROCESSES); matrix_destroy(NEED, NUMBER_OF_PROCESSES); return 0; }
void farmerProblem() { int movers, i, location, newlocation; int route[16],temproute[16],temp=0; //用于记录已考虑的状态路径 //route数组的作用是储存位置状态的值, PSeqQueue moveTo; //用于记录可以安全到达的中间状态 moveTo = createEmptyQueue_seq( );//创建空队列 enQueue_seq(moveTo, 0x00); //初始状态进队列 for (i = 0; i < 16; i++) route[i] = -1; //准备数组route初值 route[0]=0; while (!isEmptyQueue_seq(moveTo)&&(route[15] == -1)) { location = frontQueue_seq(moveTo); //取队首状态为当前状态 deQueue_seq(moveTo); for (movers = 1; movers <= 8; movers <<= 1) { //考虑各种物品移动 if ((0 != (location & 0x08)) == (0 != (location & movers))) { //农夫与移动的物品在同一侧 newlocation = location^(0x08|movers); //异或计算新状态 如初始状态下为 0000^(1000|0001) = 1001 if (safe(newlocation) && (route[newlocation] == -1)) { //新状态安全且未处理 route[newlocation] = location; //记录新状态的前驱 enQueue_seq(moveTo, newlocation); //新状态入队 } } } } //到达最终状态 if(route[15] != -1) { printf("The reverse path is : \n"); for(location = 15; location >= 0; location = route[location]) { temproute[temp]=location; ++temp; printf("The location is : %d\n",location); if (location == 0) { for(temp=7; temp>=0; --temp) { //printf("%d\n",temproute[temp]); printbinary(temproute[temp]); printf("\n"); } return; } } } else printf("No solution.\n"); }
int nqueens(int y) { int x; for (x = 0; x < QUEENS; x++) { if (safe((row[y - 1] = x), y - 1)) { if (y < QUEENS) { nqueens(y + 1); } else { break; } } } return 0; }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ Copy // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Does an generic image transfer from one canvas to another // Assumes the source rect is all on the source canvas and is valid (left<=right && top<=bottom) // Clips the other rect and dest void CBLCanvas::Copy( CCanvas *inSourceCanvas, const Rect &inCopyRect, SInt16 inDestX, SInt16 inDestY) { // Quick check of the params for null copies... if (inDestX>=mABCRec.width || inDestY>=mABCRec.height) return; if (FRectWidth(inCopyRect)==0 || FRectHeight(inCopyRect)==0) return; // Calc the dest rect Rect destRect=inCopyRect; Rect srcRect=inCopyRect; inDestX-=destRect.left; inDestY-=destRect.top; FOffset(destRect,inDestX,inDestY); // Clip? // We know the top left of the dest rect is on the canvas, but the bottom right? if (destRect.right>GetWidth()) { srcRect.right-=destRect.right-GetWidth(); destRect.right-=destRect.right-GetWidth(); } if (destRect.bottom>GetHeight()) { srcRect.bottom-=destRect.bottom-GetHeight(); destRect.bottom-=destRect.bottom-GetHeight(); } // And invoke the mighty CopyBits - or BlastCopy16 if (GetDepth()==16 && ((CBLCanvas*)inSourceCanvas)->GetDepth()==16) ::BlastCopy16(&((CBLCanvas*)inSourceCanvas)->mABCRec.rec,&mABCRec.rec,&srcRect,&destRect); else { UWorldSaver safe(mWorld); ::RGBForeColour(&TColourPresets::kBlack); ::RGBBackColour(&TColourPresets::kWhite); ::CopyBits((BitMap*)*((CBLCanvas*)inSourceCanvas)->mABCRec.rec.pixMap,(BitMap*)*mABCRec.rec.pixMap,&srcRect,&destRect,srcCopy,0L); } if (mInvalCanvasAsDraw) InvalCanvasRect(destRect); }
void int32func (const unsigned char p_10) { if (foo (~ (p_10 | (*g_282[(unsigned long) g_397 % 8][(unsigned) g_22 % 10][g_348 % 1]) == (*g_282[(unsigned long) g_397 % 8][(unsigned) g_22 % 10][g_348 % 1])), 1)) { } else if (*g_330 >= safe (*g_23 ^ (**g_282[(unsigned long) g_397 % 8][(unsigned) g_22 % 10] [g_348 % 1])) & **g_282[8][10][1], 1) { } }
// ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // ¥ UpdateDragHilite // ÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑÑ // Updates the current drag hilite. // Call if you've erased it void CStdDragAndDrop::UpdateDragHilite(RgnHandle inErasedRgn) { if (mIsHilited) { StRegion hiliteRgn(GetDragHiliteRgn(),false); StRegion resultRgn(inErasedRgn); resultRgn&=hiliteRgn; mPane->FocusDraw(); UForeColourSaver safe(TColourPresets::kWhite); ::PaintRgn(resultRgn); ::UpdateDragHilite(mDragRef,resultRgn); } }
//******************** int main(){ for(int i=0;i<3;i++) printf("%d ",available[i]); printf("\n"); for(int i=0;i<4;i++){ for(int j=0;j<3;j++){ printf("%d ",alloc[i][j]); //printf("%d ",claim[i][j]); } printf("\n"); } printf("\nis safe : %d",safe()); return 0; }//End Main
void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL, VARIANT* Flags, VARIANT* TargetFrameName, VARIANT* PostData, VARIANT* Headers, BOOL* Cancel) { ASSERT(V_VT(URL) == VT_BSTR); ASSERT(V_VT(TargetFrameName) == VT_BSTR); ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF)); ASSERT(V_VT(Headers) == VT_BSTR); ASSERT(Cancel != NULL); USES_CONVERSION; VARIANT* vtPostedData = V_VARIANTREF(PostData); CByteArray array; if (V_VT(vtPostedData) & VT_ARRAY) { // must be a vector of bytes ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1); vtPostedData->vt |= VT_UI1; COleSafeArray safe(vtPostedData); DWORD dwSize = safe.GetOneDimSize(); LPVOID pVoid; safe.AccessData(&pVoid); array.SetSize(dwSize); LPBYTE lpByte = array.GetData(); memcpy(lpByte, pVoid, dwSize); safe.UnaccessData(); } // make real parameters out of the notification CString strTargetFrameName(V_BSTR(TargetFrameName)); CString strURL = V_BSTR(URL); CString strHeaders = V_BSTR(Headers); DWORD nFlags = V_I4(Flags); // notify the user's class OnBeforeNavigate2(strURL, nFlags, strTargetFrameName, array, strHeaders, Cancel); }