//***************************************************************************** // //! Determines the intersection of two rectangles. //! //! \param rect1 is a pointer to the first rectangle. //! \param rect2 is a pointer to the second rectangle. //! \param intersect is a pointer to a rectangle which will be written with //! the intersection of \e rect1 and \e rect2. //! //! This function determines if two rectangles overlap and, if they do, //! calculates the rectangle representing their intersection. If the rectangles //! do not overlap, 0 is returned and \e intersect is not written. //! //! \return Returns 1 if there is an overlap or 0 if not. // //***************************************************************************** int32_t Graphics_getRectangleIntersection(Graphics_Rectangle *rect1, Graphics_Rectangle *rect2, Graphics_Rectangle *intersect) { // // Make sure we were passed valid rectangles. // if((rect1->xMax <= rect1->xMin) || (rect1->yMax <= rect1->yMin) || (rect2->xMax <= rect2->xMin) || (rect2->yMax <= rect2->yMin)) { return(0); } // // Make sure that there is an intersection between the two rectangles. // if(!Graphics_isRectangleOverlap(rect1, rect2)) { return(0); } // // The rectangles do intersect so determine the rectangle of the // intersection. // intersect->xMin = max(rect1->xMin, rect2->xMin); intersect->xMax = min(rect1->xMax, rect2->xMax); intersect->yMin = max(rect1->yMin, rect2->yMin); intersect->yMax = min(rect1->yMax, rect2->yMax); return(1); }

unsigned long sn_gettimeoffset(void) { long current_rtc, elapsed_rtc, old, new_offset; do { old = rtc_offset; current_rtc = GET_RTC_COUNTER(); /* * Need to address wrapping here! */ elapsed_rtc = (long)(current_rtc - last_wall_rtc); /* * This case is non lethal as the max() will take care of it. */ #if 0 if (elapsed_rtc < 0) { printk(KERN_ERR "sn_gettimeoffset(): time goes " "backwards!\n current_rtc 0x%016lx, " "last_wall_rtc 0x%016lx, elapsed %08lx, " "offset %li\n", current_rtc, last_wall_rtc, elapsed_rtc, max(elapsed_rtc, rtc_offset)/ rtc_cycles_per_usec); } #endif new_offset = max(elapsed_rtc, old); } while (cmpxchg(&rtc_offset, old, new_offset) != old); return new_offset / rtc_cycles_per_usec; }

int FindCrossMax(int *nums, int low, int mid, int high) { int index; int lsum = INT_MIN; int rsum = INT_MIN; int sum = 0; for (index = mid; index > low; index--) { sum += nums[index]; if (sum > lsum) { lsum = sum; } } sum = 0; for (index = mid; index < high; index++) { sum += nums[index]; if (sum > rsum) { rsum = sum; } } lsum = max(lsum,0); rsum = max(rsum,0); return (lsum+rsum); }

int AlphaBetaPruning::AlphaBetaMax(Board &BBoard, int Depth, ePlayer eCurrentPlayer) { Move m[8]; int iNumberOfValidMoves = FillValidMoves(m, BBoard); int iRetValue; if (Depth == 0 || iNumberOfValidMoves == 0) { iRetValue = BBoard.Evaluate(eCurrentPlayer); goto ret; } int iMaxValue = -INF; for (int i = 0; i < iNumberOfValidMoves; i++) { Move &x = m[i]; BBoard.ReflectMove(x, eCurrentPlayer); iMaxValue = max(iMaxValue, AlphaBetaMin(BBoard, Depth - 1, eCurrentPlayer)); BBoard.RemoveMove(x); if (iMaxValue >= m_iBeta) { iRetValue = m_iAlpha; goto ret; } m_iAlpha = max(m_iAlpha, iMaxValue); } iRetValue = iMaxValue; ret: return iRetValue; }

void model_parameters::preliminary_calculations(void) { #if defined(USE_ADPVM) admaster_slave_variable_interface(*this); #endif // get the data out of the columns of the data matrix landings=column(data,1); biomass=column(data,2); // calculate observed surplus production (Pobs) for(int i=1;i<=nobs-1;i++) { Pobs(i)=biomass(i+1)-biomass(i)+landings(i); } // set starting values lnMSY=log(0.6*max(Pobs)); lnK=log(max(biomass)); n=2; }

void center_model(model *m) { vec_3D maximum, minimum; maximum.x = m->vertices[0]; maximum.y = m->vertices[1]; maximum.z = m->vertices[2]; minimum.x = m->vertices[0]; minimum.y = m->vertices[1]; minimum.z = m->vertices[2]; for(uint i = 0; i < m->n_vertices; i++){ maximum.x = max(maximum.x,m->vertices[3*i + 0]); maximum.y = max(maximum.y,m->vertices[3*i + 1]); maximum.z = max(maximum.z,m->vertices[3*i + 2]); minimum.x = min(minimum.x, m->vertices[3*i + 0]); minimum.y = min(minimum.y, m->vertices[3*i + 1]); minimum.z = min(minimum.z, m->vertices[3*i + 2]); } for(uint i = 0; i < m->n_vertices; i++){ m->vertices[3*i + 0] -= (maximum.x + minimum.x)/2; m->vertices[3*i + 1] -= (maximum.y + minimum.y)/2; m->vertices[3*i + 2] -= (maximum.z + minimum.z)/2; } }

void ErodeDistanceOperation::executePixel(float *color, int x, int y, void *data) { const float distance = this->m_distance; const float mindist = distance * distance; MemoryBuffer *inputBuffer = (MemoryBuffer *)data; float *buffer = inputBuffer->getBuffer(); rcti *rect = inputBuffer->getRect(); const int minx = max(x - this->m_scope, rect->xmin); const int miny = max(y - this->m_scope, rect->ymin); const int maxx = min(x + this->m_scope, rect->xmax); const int maxy = min(y + this->m_scope, rect->ymax); const int bufferWidth = rect->xmax - rect->xmin; int offset; float value = 1.0f; for (int yi = miny; yi < maxy; yi++) { const float dy = yi - y; offset = ((yi - rect->ymin) * bufferWidth + (minx - rect->xmin)) * 4; for (int xi = minx; xi < maxx; xi++) { const float dx = xi - x; const float dis = dx * dx + dy * dy; if (dis <= mindist) { value = min(buffer[offset], value); } offset += 4; } } color[0] = value; }

int* CellsRegistry::reserveRandomAvailableGroundPosAround(int* returnPos, int parentX, int parentY, int sqrLen){ int xMin = max(0, parentX-sqrLen); int xMax = min(world.length-1, parentX+sqrLen); int yMin = max(0, parentY-sqrLen); int yMax = min(world.length-1, parentY+sqrLen); int nbAvailablePos = 0; for (int i=xMin; i<=xMax; ++i){ for (int j=yMin; j<=yMax; ++j){ if (registryXYZ[i][j][0] == NULL){ availablePosTmp[nbAvailablePos][0] = i; availablePosTmp[nbAvailablePos][1] = j; ++nbAvailablePos; } } } if (nbAvailablePos == 0) return NULL; int i = randInt(nbAvailablePos); returnPos[0] = availablePosTmp[i][0]; returnPos[1] = availablePosTmp[i][1]; return returnPos; }

/************************************************************************* * * \函数名称： * DirGrad() * * \输入参数: * unsigned char *pUnchSmthdImg - 经过高斯滤波后的图象 * int nWidht - 图象宽度 * int nHeight - 图象高度 * int *pnGradX - x方向的方向导数 * int *pnGradY - y方向的方向导数 * \返回值: * 无 * * \说明: * 这个函数计算方向倒数，采用的微分算子是(-1 0 1) 和 (-1 0 1)'(转置) * 计算的时候对边界象素采用了特殊处理 * * ************************************************************************* */ void DirGrad(unsigned char *pUnchSmthdImg, int nWidth, int nHeight, int *pnGradX , int *pnGradY) { // 循环控制变量 int y ; int x ; // 计算x方向的方向导数，在边界出进行了处理，防止要访问的象素出界 for(y=0; y<nHeight; y++) { for(x=0; x<nWidth; x++) { pnGradX[y*nWidth+x] = (int) ( pUnchSmthdImg[y*nWidth+min(nWidth-1,x+1)] - pUnchSmthdImg[y*nWidth+max(0,x-1)] ); } } // 计算y方向的方向导数，在边界出进行了处理，防止要访问的象素出界 for(x=0; x<nWidth; x++) { for(y=0; y<nHeight; y++) { pnGradY[y*nWidth+x] = (int) ( pUnchSmthdImg[min(nHeight-1,y+1)*nWidth + x] - pUnchSmthdImg[max(0,y-1)*nWidth+ x ] ); } } }

LONG cIntersect( RECTL* prclClip, RECTL* prclIn, // List of rectangles LONG c) // Can be zero { LONG cIntersections; RECTL* prclOut; cIntersections = 0; prclOut = prclIn; for (; c != 0; prclIn++, c--) { prclOut->left = max(prclIn->left, prclClip->left); prclOut->right = min(prclIn->right, prclClip->right); if (prclOut->left < prclOut->right) { prclOut->top = max(prclIn->top, prclClip->top); prclOut->bottom = min(prclIn->bottom, prclClip->bottom); if (prclOut->top < prclOut->bottom) { prclOut++; cIntersections++; } } } return(cIntersections); }

HRESULT CBaseSplitterOutputPin::DecideBufferSize(IMemAllocator* pAlloc, ALLOCATOR_PROPERTIES* pProperties) { ASSERT(pAlloc); ASSERT(pProperties); HRESULT hr = NOERROR; pProperties->cBuffers = max(pProperties->cBuffers, m_nBuffers); pProperties->cbBuffer = max(m_mt.lSampleSize, 1); // TODO: is this still needed ? if (m_mt.subtype == MEDIASUBTYPE_Vorbis && m_mt.formattype == FORMAT_VorbisFormat) { // oh great, the oggds vorbis decoder assumes there will be two at least, stupid thing... pProperties->cBuffers = max(pProperties->cBuffers, 2); } ALLOCATOR_PROPERTIES Actual; if (FAILED(hr = pAlloc->SetProperties(pProperties, &Actual))) { return hr; } if (Actual.cbBuffer < pProperties->cbBuffer) { return E_FAIL; } ASSERT(Actual.cBuffers == pProperties->cBuffers); return NOERROR; }

int main(){ int c, t,h,f, i,j,k, ha; scanf("%d", &c); while(c--){ scanf("%d %d %d", &t, &h, &f); memset(acorn, 0, sizeof acorn); for(i=0; i<t; i++){ scanf("%d", &k); for(j=0; j<k; j++) { scanf("%d", &ha); acorn[i][ha]++; } } memset(dp, 0, sizeof dp); for(i=0; i<t; i++) dp[h]=max(dp[h], acorn[i][h]); for(i=h-1; i>=0; i--){ for(j=0; j<t; j++){ acorn[j][i]+=max(acorn[j][i+1], ((i+f<=h)?dp[i+f]:0)); dp[i]=max(dp[i], acorn[j][i]); } } printf("%d\n", dp[0]); } return 0; }

void CDiamond::NormalizeGraphData() { if(m_ptary[4].Equals(m_ptary[5]) && m_bFinish) { m_ptary[4].X -= 50; m_ptary[4].Y -= 50; m_ptary[5].X += 50; m_ptary[5].Y += 50; } PointF ptCenter((m_ptary[4].X + m_ptary[5].X) / 2, (m_ptary[4].Y + m_ptary[5].Y) / 2); float fTop = min(m_ptary[4].Y, m_ptary[5].Y); float fBottom = max(m_ptary[4].Y, m_ptary[5].Y); float fLeft = min(m_ptary[4].X, m_ptary[5].X); float fRight = max(m_ptary[4].X, m_ptary[5].X); m_ptary[0].X = fLeft; m_ptary[0].Y = ptCenter.Y; m_ptary[1].X = ptCenter.X; m_ptary[1].Y = fTop; m_ptary[2].X = fRight; m_ptary[2].Y = ptCenter.Y; m_ptary[3].X = ptCenter.X; m_ptary[3].Y = fBottom; }

static void _SC_array_grow(SC_array *a, long nn, long ng) {int chg; long i, n, nx, bpi; double gf, fc, ex; char *arr; void *e; arr = (char *) a->array; nx = a->nx; bpi = a->bpi; chg = FALSE; /* if growth size not specified - grow exponentially from the old size */ if (ng < 0) {n = max(nx, a->n); n = max(n, nn); gf = a->gf; ex = -gf*n; fc = pow(2.0, ex); nn = (n + 1)*(1.0 + fc);}; /* if never allocated */ if (arr == NULL) {if (nn == 0) {nx = 0; nn = 1;}; arr = CPMAKE_N(char, nn*bpi, a->memfl); chg = TRUE;} /* if too small */ else if (nn > nx)

int main() { int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%lf%lf", &v1[i], &v2[i]); qsort(v1+1, n, sizeof(double), cmp); qsort(v2+1, n, sizeof(double), cmp); double s1=0, s2=0, sol=0; int c=0, l=n; for(int i=n; i>=1; i--) { s1 += v1[i]; c++; sol = max(sol,min(s1-c,s2-c)); while(l>=1 && s2-c<s1-c) { s2 += v2[l]; c++; sol = max(sol,min(s1-c,s2-c)); l--; } } printf("%.4f", sol); return 0; }

void CMarkup::x_DocChange( int nLeft, int nReplace, const INXString& csInsert ) { // Insert csInsert int m_csDoc at nLeft replacing nReplace chars // Do this with only one buffer reallocation if it grows // int nDocLength = m_csDoc.GetLength(); int nInsLength = csInsert.GetLength(); // Make sure nLeft and nReplace are within bounds nLeft = max( 0, min( nLeft, nDocLength ) ); nReplace = max( 0, min( nReplace, nDocLength-nLeft ) ); // Get pointer to buffer with enough room int nNewLength = nInsLength + nDocLength - nReplace; int nBufferLen = nNewLength; char* pDoc = m_csDoc.GetBuffer( nBufferLen ); // Move part of old doc that goes after insert if ( nLeft+nReplace < nDocLength ) memmove( &pDoc[nLeft+nInsLength], &pDoc[nLeft+nReplace], (nDocLength-nLeft-nReplace)*sizeof(char) ); // Copy insert //const char* tempChar = csInsert; memcpy( &pDoc[nLeft], (const char*)csInsert, nInsLength*sizeof(char)); // Release m_csDoc.ReleaseBuffer( nNewLength ); }

int main() { FILE *in,*out; int n,m; int i,j,k,l,x; int a[5]; int w[351]; in=fopen("tortoise.in","r"); out=fopen("tortoise.out","w+"); fscanf(in,"%d%d",&n,&m); memset(a,0,sizeof(a)); memset(w,0,sizeof(w)); for (i=1;i<=n;i++) fscanf(in,"%d",&w[i]); for (i=1;i<=m;i++) {fscanf(in,"%d",&x);++a[x];} for (i=0;i<=a[1];i++) for (j=0;j<=a[2];j++) for (k=0;k<=a[3];k++) for (l=0;l<=a[4];l++) { int t=0,dis; dis=1+i+(j<<1)+(k*3)+(l<<2); if (i) t=max(t,f[i-1][j][k][l]); if (j) t=max(t,f[i][j-1][k][l]); if (k) t=max(t,f[i][j][k-1][l]); if (l) t=max(t,f[i][j][k][l-1]); f[i][j][k][l]=t+w[dis]; } fprintf(out,"%d\n",f[a[1]][a[2]][a[3]][a[4]]); fclose(in); fclose(out); return 0; }

int trapRainWater(vector<vector<int>>& heightMap) { if (heightMap.size() < 3 || heightMap[0].size() < 3) { return 0; } int row = (int)(heightMap.size()); int col = (int)(heightMap[0].size()); initialize(heightMap, row, col); int result = 0; while (pq.size() > 0) { Triple top = pq.top(); pq.pop(); // loop 4 directions for (auto dir: directions) { int new_x = top.x + dir[0]; int new_y = top.y + dir[1]; int point = convertPoint(new_x, new_y, col); if (inBoundary(new_x, new_y, heightMap) && visited.count(point) == 0) { int new_height = heightMap[new_x][new_y]; result += max(0, top.height - new_height); add(max(top.height, new_height), new_x, new_y, col); } } } return result; }

int main(){ int t,x,y,xx,yy,x1,y1,xx1,yy1,X,Y,XX,YY; int line = 0; scanf("%d", &t); while(t--){ scanf("%d %d %d %d", &x, &y, &xx, &yy); scanf("%d %d %d %d", &x1, &y1, &xx1, &yy1); X = max(x, x1); Y = max(y, y1); XX = min(xx, xx1); YY = min(yy, yy1); if(line) printf("\n"); line = 1; if(X < XX && Y < YY) printf("%d %d %d %d\n", X, Y, XX, YY); else printf("No Overlap\n"); } return 0; }

void Drive_Arcade(Motor_Speed moveSpeed, Motor_Speed rotateSpeed) { Motor_Speed leftMotorSpeed; Motor_Speed rightMotorSpeed; // Do the calculations for arcade drive. if (moveSpeed > 0) { if (rotateSpeed > 0) { leftMotorSpeed = moveSpeed - rotateSpeed; rightMotorSpeed = max(moveSpeed, rotateSpeed); } else { leftMotorSpeed = max(moveSpeed, -rotateSpeed); rightMotorSpeed = moveSpeed + rotateSpeed; } } else { if (rotateSpeed > 0) { leftMotorSpeed = -max(-moveSpeed, rotateSpeed); rightMotorSpeed = moveSpeed + rotateSpeed; } else { leftMotorSpeed = moveSpeed - rotateSpeed; rightMotorSpeed = -max(-moveSpeed, -rotateSpeed); } } // Drive the left and right sides of the robot at the specified speeds. Drive_Tank(leftMotorSpeed, rightMotorSpeed); }

void BrowCtx::zoom( double factor) { if ( fabs(factor) < DBL_EPSILON) return; mw.zoom_factor_x *= factor; mw.zoom_factor_y *= factor; if ( mw.offset_x != 0) mw.offset_x = int( (mw.offset_x - mw.window_width / 2.0 * ( 1.0/factor - 1)) * factor); if ( mw.offset_y != 0) mw.offset_y = int( (mw.offset_y - mw.window_height / 2.0 * ( 1.0/factor - 1)) * factor); mw.offset_x = max( mw.offset_x, 0); mw.offset_y = max( mw.offset_y, 0); if ( (x_right - x_left) * mw.zoom_factor_x <= mw.window_width) mw.offset_x = 0; if ( (y_high - y_low) * mw.zoom_factor_y <= mw.window_height) mw.offset_y = 0; a.zoom(); clear( &mw); draw( &mw, 0, 0, mw.window_width, mw.window_height); nav_zoom(); change_scrollbar(); }

float calculate_likelihood(float x, float y, float theta, float z) { int closestWallIndex = -1; // We take into consideration the greatest distance float shortestDistance = 20000.0; float m; int i = 0; for (i = 0; i < NUMBER_OF_WALLS; i++) { float a_x = wallAxArray[i], a_y = wallAyArray[i]; float b_x = wallBxArray[i], b_y = wallByArray[i]; m = ((b_y - a_y)*(a_x - x) - (b_x - a_x)*(a_y - y)) / ((b_y - a_y)*cosDegrees(theta) - (b_x - a_x)*sinDegrees(theta)); float px = x + m*cosDegrees(theta); float py = y + m*sinDegrees(theta); if( px >= min(a_x,b_x) && px <= max(a_x,b_x) && py >= min(a_y,b_y) && py <= max(a_y,b_y) && m >= 0) { if ( m <= shortestDistance ) { shortestDistance = m; closestWallIndex = i; } } } float likelihood = exp(-pow(z - shortestDistance, 2) * 1.0 / (2 * pow(0.44, 2))) + 0.1; return likelihood; }

int lengthOfLongestSubstring(string s) { if(s.length()==0) return 0; int i=0, len=0, maxlen=0, start=0; unordered_map<char, int> m; while(i < s.length()){ if(m.find(s[i]) == m.end() || m[s[i]] < start){ m[s[i]] = i; ++len; } else{ maxlen = max(len, maxlen); start= m[s[i]] + 1; len = i - m[s[i]]; m[s[i]]= i; } ++i; } maxlen= max(maxlen, len); return maxlen; }

/** Purpose ------- CPOSV computes the solution to a complex system of linear equations A * X = B, where A is an N-by-N Hermitian positive definite matrix and X and B are N-by-NRHS matrices. The Cholesky decomposition is used to factor A as A = U**H * U, if UPLO = MagmaUpper, or A = L * L**H, if UPLO = MagmaLower, where U is an upper triangular matrix and L is a lower triangular matrix. The factored form of A is then used to solve the system of equations A * X = B. Arguments --------- @param[in] uplo magma_uplo_t - = MagmaUpper: Upper triangle of A is stored; - = MagmaLower: Lower triangle of A is stored. @param[in] n INTEGER The order of the matrix A. N >= 0. @param[in] nrhs INTEGER The number of right hand sides, i.e., the number of columns of the matrix B. NRHS >= 0. @param[in,out] dA COMPLEX array on the GPU, dimension (LDDA,N) On entry, the Hermitian matrix dA. If UPLO = MagmaUpper, the leading N-by-N upper triangular part of dA contains the upper triangular part of the matrix dA, and the strictly lower triangular part of dA is not referenced. If UPLO = MagmaLower, the leading N-by-N lower triangular part of dA contains the lower triangular part of the matrix dA, and the strictly upper triangular part of dA is not referenced. \n On exit, if INFO = 0, the factor U or L from the Cholesky factorization dA = U**H*U or dA = L*L**H. @param[in] ldda INTEGER The leading dimension of the array A. LDA >= max(1,N). @param[in,out] dB COMPLEX array on the GPU, dimension (LDB,NRHS) On entry, the right hand side matrix B. On exit, the solution matrix X. @param[in] lddb INTEGER The leading dimension of the array B. LDB >= max(1,N). @param[out] info INTEGER - = 0: successful exit - < 0: if INFO = -i, the i-th argument had an illegal value @ingroup magma_cposv_driver ********************************************************************/ extern "C" magma_int_t magma_cposv_gpu( magma_uplo_t uplo, magma_int_t n, magma_int_t nrhs, magmaFloatComplex_ptr dA, magma_int_t ldda, magmaFloatComplex_ptr dB, magma_int_t lddb, magma_int_t *info ) { *info = 0; if ( uplo != MagmaUpper && uplo != MagmaLower ) *info = -1; if ( n < 0 ) *info = -2; if ( nrhs < 0 ) *info = -3; if ( ldda < max(1, n) ) *info = -5; if ( lddb < max(1, n) ) *info = -7; if (*info != 0) { magma_xerbla( __func__, -(*info) ); return *info; } /* Quick return if possible */ if ( (n == 0) || (nrhs == 0) ) { return *info; } magma_cpotrf_gpu( uplo, n, dA, ldda, info ); if ( *info == 0 ) { magma_cpotrs_gpu( uplo, n, nrhs, dA, ldda, dB, lddb, info ); } return *info; }

void SubPlotWnd::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (this->isDraging) { CPoint cursorPoint; ::GetCursorPos(&cursorPoint); CPoint cursorPointOld = cursorPoint; CRect parentClientRect; this->GetParent()->GetClientRect(&parentClientRect); this->GetParent()->ClientToScreen(&parentClientRect); cursorPoint.x = max(cursorPoint.x, parentClientRect.left); cursorPoint.x = min(cursorPoint.x, parentClientRect.right); cursorPoint.y = max(cursorPoint.y, parentClientRect.top); cursorPoint.y = min(cursorPoint.y, parentClientRect.bottom); if (cursorPoint != cursorPointOld) ::SetCursorPos(cursorPoint.x, cursorPoint.y); CRect rectWindow = this->rectBeforeDrag; rectWindow.OffsetRect(cursorPoint - this->cursorBeforeDrag); this->MoveWindow(rectWindow.left, rectWindow.top, rectWindow.Width(), rectWindow.Height(), 1); CWnd::OnMouseMove(nFlags, point); } }

float3 CAICallback::ClosestBuildSite(const UnitDef* unitdef,float3 pos,float searchRadius,int minDist) { //todo fix so you cant detect enemy buildings with it CFeature* feature; int allyteam=gs->AllyTeam(team); int endr = (int)(searchRadius / (SQUARE_SIZE*2)); const vector<SearchOffset>& ofs = GetSearchOffsetTable (endr); for(int so=0;so<endr*endr*4;so++) { float x = pos.x+ofs[so].dx*SQUARE_SIZE*2; float z = pos.z+ofs[so].dy*SQUARE_SIZE*2; float3 p(x,0,z); p = helper->Pos2BuildPos (p, unitdef); if(uh->TestUnitBuildSquare(p,unitdef,feature) && (!feature || feature->allyteam!=allyteam)) { int xs=(int)(x/SQUARE_SIZE); int zs=(int)(z/SQUARE_SIZE); bool good=true; for(int z2=max(0,zs-unitdef->ysize/2-minDist);z2<min(gs->mapy,zs+unitdef->ysize+minDist);++z2){ for(int x2=max(0,xs-unitdef->xsize/2-minDist);x2<min(gs->mapx,xs+unitdef->xsize+minDist);++x2){ CSolidObject* so=readmap->groundBlockingObjectMap[z2*gs->mapx+x2]; if(so && so->immobile && !dynamic_cast<CFeature*>(so)){ good=false; break; } } } if(good) return p; } } return float3(-1.0f,0.0f,0.0f); }

/* vdd_core must be >= min_level as a function of vdd_cpu */ static int tegra3_dvfs_rel_vdd_cpu_vdd_core(struct dvfs_rail *vdd_cpu, struct dvfs_rail *vdd_core) { int core_floor = max(vdd_cpu->new_millivolts, vdd_cpu->millivolts); core_floor = tegra3_get_core_floor_mv(core_floor); return max(vdd_core->new_millivolts, core_floor); }

static BOOL vrdpIntersectRectWithBounds (RECTL *prclIntersect, const RECTL *prcl, const VRDEORDERBOUNDS *pBounds) { if ( prcl->left < pBounds->pt2.x /* left < bounds_right */ && prcl->right > pBounds->pt1.x /* right < bounds_left */ && prcl->top < pBounds->pt2.y /* top < bounds_bottom */ && prcl->bottom > pBounds->pt1.y /* bottom < bounds_top */ ) { /* There is intersection. */ prclIntersect->left = max(prcl->left, pBounds->pt1.x); prclIntersect->right = min(prcl->right, pBounds->pt2.x); prclIntersect->top = max(prcl->top, pBounds->pt1.y); prclIntersect->bottom = min(prcl->bottom, pBounds->pt2.y); Assert(prclIntersect->left < prclIntersect->right); Assert(prclIntersect->top < prclIntersect->bottom); return TRUE; } /* No intersection. */ return FALSE; }

int longestValidParentheses(string s) { if(s.size() <= 1) return 0; stack<int> lefts; int leftmost = -1; int longest = 0; int i; for(i = 0; i < s.size(); i++){ if(s[i] == '('){ lefts.push(i); } else{ // must be ')' if(lefts.empty()) leftmost = i; else{ lefts.pop(); if(lefts.empty()){ longest = max(longest, i-leftmost); } else{ longest = max(longest, i-lefts.top()); } } } } return longest; }

int longestValidParentheses(string s) { stack<pair<char, int>> charStack; vector<bool> valid(s.size(), false); for (int i = 0; i < s.size(); i++) { if ( !charStack.empty() ) { char topChar = charStack.top().first; int topPos = charStack.top().second; if( topChar == '(' && s[i] == ')') { charStack.pop(); for (int j = topPos; j <= i; ++j) { valid[j] = true; } } else { charStack.push(make_pair(s[i], i)); } } else { charStack.push(make_pair(s[i], i)); } } int nowLen = 0; int maxLen = 0; for (int i = 0; i < s.size(); ++i) { if(valid[i]) { nowLen++; } else { maxLen = max(maxLen, nowLen); nowLen = 0; } } maxLen = max(maxLen, nowLen); return maxLen; }