int trap(int A[], int n) { vector<int> left(n,0),right(n,0); int max=0; for(int i=0;i<n;++i) { left[i] = max; if(max<A[i]) max=A[i]; } max = 0; for(int i=n-1;i>=0;--i) { right[i] = max; if(max<A[i]) max=A[i]; } vector<int> filled(n,0),dif(n,0); int ret = 0; for(int i=0;i<n;++i) { filled[i] = min(left[i],right[i]); dif[i] = filled[i]-A[i]; if(dif[i]>0) ret += dif[i]; } return ret; }
Task* LoadTask(char* name) { // modif quand CMD.wd FILE* t; CMD command; char task[1024]; char* ptr_on_wd; Task* tsk = NotUsed(); if (tsk!=NULL) { sprintf(task, "%s/%s", PATH_TO_TASKS, name); t = fopen(task, "r"); if (t!=NULL) { strncpy(tsk->id, name, 64); setEmpty(&(tsk->q)); tsk->inuse=1; tsk->exec=0; tsk->demand=0; while (fgets(command.cmd, 1024, t)!=NULL) { CleanLineFeed(command.cmd); if ((ptr_on_wd=strchr(command.cmd, '#'))!=NULL) { *ptr_on_wd='\0'; sprintf(command.wd, "%s", ptr_on_wd+1); } else command.wd[0]='\0'; if (!filled(&(tsk->q))) addTail(&(tsk->q), command); } fclose(t); sha->loaded++; return tsk; } } return NULL; }
BOOL CDlgImageViewer::OnEraseBkgnd(CDC* pDC) { // TODO: 在此添加消息处理程序代码和/或调用默认值 CRect rect; GetClientRect(&rect); // 工具栏和窗口之间留一条空隙。 CRect filled(0, 23, rect.right, 24); pDC->FillSolidRect(&filled, RGB(255,255,255)); return TRUE; }
nsresult imgFrame::Extract(const nsIntRect& aRegion, imgFrame** aResult) { nsAutoPtr<imgFrame> subImage(new imgFrame()); if (!subImage) return NS_ERROR_OUT_OF_MEMORY; // The scaling problems described in bug 468496 are especially // likely to be visible for the sub-image, as at present the only // user is the border-image code and border-images tend to get // stretched a lot. At the same time, the performance concerns // that prevent us from just using Cairo's fallback scaler when // accelerated graphics won't cut it are less relevant to such // images, since they also tend to be small. Thus, we forcibly // disable the use of anything other than a client-side image // surface for the sub-image; this ensures that the correct // (albeit slower) Cairo fallback scaler will be used. subImage->mNeverUseDeviceSurface = PR_TRUE; nsresult rv = subImage->Init(0, 0, aRegion.width, aRegion.height, mFormat, mPaletteDepth); NS_ENSURE_SUCCESS(rv, rv); // scope to destroy ctx { gfxContext ctx(subImage->ThebesSurface()); ctx.SetOperator(gfxContext::OPERATOR_SOURCE); if (mSinglePixel) { ctx.SetDeviceColor(mSinglePixelColor); } else { // SetSource() places point (0,0) of its first argument at // the coordinages given by its second argument. We want // (x,y) of the image to be (0,0) of source space, so we // put (0,0) of the image at (-x,-y). ctx.SetSource(this->ThebesSurface(), gfxPoint(-aRegion.x, -aRegion.y)); } ctx.Rectangle(gfxRect(0, 0, aRegion.width, aRegion.height)); ctx.Fill(); } nsIntRect filled(0, 0, aRegion.width, aRegion.height); rv = subImage->ImageUpdated(filled); NS_ENSURE_SUCCESS(rv, rv); subImage->Optimize(); *aResult = subImage.forget(); return NS_OK; }
static void db_thread(EFSSyncRef const sync) { int rc; struct queues *cur; for(;;) { if(sync->stop) break; async_mutex_lock(sync->mutex); // First we wait for anything to enter the queue. // Then we wait an additional LATENCY_MAX for // the queue to fill completely before processing. while(empty(sync)) { rc = async_cond_wait(sync->cond, sync->mutex); if(UV_ECANCELED == rc) { async_mutex_unlock(sync->mutex); return; // TODO } } uint64_t const future = uv_now(loop) + LATENCY_MAX; while(!filled(sync)) { rc = async_cond_timedwait(sync->cond, sync->mutex, future); if(UV_ETIMEDOUT == rc) break; if(UV_ECANCELED == rc) { async_mutex_unlock(sync->mutex); return; // TODO } } // Double buffering. cur = sync->cur; sync->cur = (&sync->queues[1] == sync->cur) ? &sync->queues[0] : &sync->queues[1]; async_mutex_unlock(sync->mutex); for(;;) { rc = db_work(sync, cur); if(DB_SUCCESS == rc) break; fprintf(stderr, "Sync database error %s\n", db_strerror(rc)); async_sleep(1000 * 5); } } // TODO: Thread joining }
int main(void){ int n ; scanf("%d",&n); int arr1[n]; int arr2[n]; int arr3[n]; for(int i=0;i<n;i++){ scanf("%d",&arr1[i]); scanf("%d",&arr2[i]); scanf("%d",&arr3[i]); } for(int i=0;i<n;i++) printf("%d\n",filled( arr1[i], arr2[i], arr3[i])); return 0; }
int negamax(int board[9], int player) { // check if terminal node if (iswon(board)) return iswon(board)*player; else if (filled(board) && !iswon(board)) return 0; int best = -2; int i; for (i=0; i<9; i++) { if (board[i] == 0) { board[i] = player; int score = -negamax(board, player*-1); board[i] = 0; best = maximum(best, score); } } return best; }
void ReloadTask(char* name) { // modif quand CMD.wd Task* taskptr; FILE* t; CMD command; char task[1024]; sprintf(task, "%s/%s", PATH_TO_TASKS, name); t = fopen(task, "r"); if (t!=NULL) { if ((taskptr = GetTask(name))!=NULL) { setEmpty(&(taskptr->q)); while (fgets(command.cmd, 1024, t)!=NULL) { CleanLineFeed(command.cmd); if (!filled(&(taskptr->q))) addTail(&(taskptr->q), command); } fclose(t); } } else fprintf(stderr, "*** impossible to load %s task\n", name); }
/* * Fill binded variables from Lua * Table must be located at index position inside state stack */ bool Table::fillFromLua(lua_State *state, int index) { for(lua_pushnil(state); lua_next(state, index-1); lua_pop(state, 1)) { QString key = QString(lua_tostring(state, -2)); QString valuetype = QString(lua_typename(state, lua_type(state, -1))); if(valuetype == "string") { QString value = lua_tostring(state, index); this->insert(key, QVariant(value)); } else if(valuetype == "number") { double value = lua_tonumber(state, index); this->insert(key, QVariant(value)); } else { return false; } } emit filled(); return true; }
void AddToTask(Task* p) { p->demand=1; if (!filled(&(p->q))) addTail(&(p->q), addedCommand); p->demand=0; }
int flipLights(int n, int m) { if (n == 0 || m == 0) return 1; vector<State> states; for (int option = 0; option < 8; ++option) { vector<bool> values(n, true); for (int i = 1; i <= n; ++i) { if (option & 1) { // even if ((i & 1) == 0) { values[i-1] = !values[i-1]; } } if (option & 2) { // odd if ((i & 1) == 1) { values[i-1] = !values[i-1]; } } if (option & 4) { // 3 * K + 1 if (i % 3 == 1) { values[i-1] = !values[i-1]; } } } bool found = false; for (int i = 0; i < states.size(); ++i) { if (values == states[i].result) { states[i].options.insert(option); found = true; break; } } if (!found) { State state; state.options.insert(option); state.result = values; states.push_back(state); } } if (m >= 4) { return states.size(); } vector<bool> filled(states.size(), false); for (int d_value = 0; d_value <= m; ++d_value) { int bc_value = m - d_value; int d_option = (d_value % 2 == 0) ? 0 : 4; vector<int> bc_options; if (bc_value == 0) { bc_options.push_back(0); } else if (bc_value == 1) { bc_options.push_back(1); bc_options.push_back(2); bc_options.push_back(3); } else { bc_options.push_back(0); bc_options.push_back(1); bc_options.push_back(2); bc_options.push_back(3); } for (int i = 0; i < bc_options.size(); ++i) { int option = d_option | bc_options[i]; for (int j = 0; j < states.size(); ++j) { if (states[j].options.find(option) != states[j].options.end()) { filled[j] = true; break; } } } } int res = 0; for (int i = 0; i < filled.size(); ++i) { if (filled[i]) res++; } return res; }
void World::process_completed_chunk_update(decltype(ChunkUpdateArray::value_type::first)& chunk_update) { auto chunk = get_chunk(chunk_update->get_x(), chunk_update->get_y(), chunk_update->get_z()); if (!chunk) { // Chunk has been unloaded while we were updating it's data return; } chunk->update_mesh(chunk_update->get_vertices().data(), chunk_update->get_indices().data(), chunk_update->get_num_vertices(), chunk_update->get_num_indices()); // If this chunk has just been filled, we need to update any adjacent chunks that are now // completely surrounded. This is to achieve full obstruction culling for those chunks. auto update_chunk_if_surrounded = [this](int chunk_x, int chunk_y, int chunk_z) { Chunk* chunk = get_chunk(chunk_x, chunk_y, chunk_z); if (!chunk) { return; } Chunk* adjacent = get_chunk(chunk_x - 1, chunk_y, chunk_z); if (adjacent && !adjacent->filled()) { return; } adjacent = get_chunk(chunk_x + 1, chunk_y, chunk_z); if (adjacent && !adjacent->filled()) { return; } adjacent = get_chunk(chunk_x, chunk_y - 1, chunk_z); if (adjacent && !adjacent->filled()) { return; } adjacent = get_chunk(chunk_x, chunk_y + 1, chunk_z); if (adjacent && !adjacent->filled()) { return; } adjacent = get_chunk(chunk_x, chunk_y, chunk_z - 1); if (adjacent && !adjacent->filled()) { return; } adjacent = get_chunk(chunk_x, chunk_y, chunk_z + 1); if (adjacent && !adjacent->filled()) { return; } chunk->set_up_to_date(false); }; if (!chunk->filled()) { chunk->set_filled(true); update_chunk_if_surrounded(chunk->get_x() - 1, chunk->get_y(), chunk->get_z()); update_chunk_if_surrounded(chunk->get_x() + 1, chunk->get_y(), chunk->get_z()); update_chunk_if_surrounded(chunk->get_x(), chunk->get_y() - 1, chunk->get_z()); update_chunk_if_surrounded(chunk->get_x(), chunk->get_y() + 1, chunk->get_z()); update_chunk_if_surrounded(chunk->get_x(), chunk->get_y(), chunk->get_z() - 1); update_chunk_if_surrounded(chunk->get_x(), chunk->get_y(), chunk->get_z() + 1); } if (!chunk->reupdate()) { chunk->set_up_to_date(true); } chunk->set_update_queued(false); chunk->set_low_priority_update(false); }