bool FindStart(int y, int x, int k) { if(k > 0) { if(!PutSquares(k)) { ResetMat(); return false; } if(k == numPolys) return true; } ResetMat(); for(; y < h; ++y) { for(; x < w; ++x) { if(mat[y][x] == -1) { sx[k] = x; sy[k] = y; if(FindStart(y,x+1,k+1)) return true; } } x = 0; } return false; }
void ContestDijkstra::AddEdges(const ScanTaskPoint origin, const unsigned first_point) { ScanTaskPoint destination(origin.GetStageNumber() + 1, std::max(origin.GetPointIndex(), first_point)); const int min_altitude = IsFinal(destination) ? GetMinimumFinishAltitude(GetPoint(FindStart(origin))) : 0; if (IsFinal(destination) && first_finish_candidate > destination.GetPointIndex()) /* limit the number of finish candidates during incremental search */ destination.SetPointIndex(first_finish_candidate); const unsigned weight = GetStageWeight(origin.GetStageNumber()); for (const ScanTaskPoint end(destination.GetStageNumber(), n_points); destination != end; destination.IncrementPointIndex()) { if (GetPoint(destination).GetIntegerAltitude() >= min_altitude) { const unsigned d = weight * CalcEdgeDistance(origin, destination); Link(destination, origin, d); } } }
void OLCTriangle::AddFinishEdges(const ScanTaskPoint origin) { assert(IsFinal(origin.GetStageNumber() + 1)); if (predict) { // dummy just to close the triangle Link(ScanTaskPoint(origin.GetStageNumber() + 1, n_points - 1), origin, 0); } else { const ScanTaskPoint start = FindStart(origin); const TracePoint &start_point = GetPoint(start); const TracePoint &origin_point = GetPoint(origin); const unsigned max_range = trace_master.ProjectRange(origin_point.GetLocation(), max_distance); /* check all remaining points, see which ones match the conditions */ const ScanTaskPoint begin(origin.GetStageNumber() + 1, 0); const ScanTaskPoint end(origin.GetStageNumber() + 1, origin.GetPointIndex()); for (ScanTaskPoint i = begin; i != end; i.IncrementPointIndex()) if (CalcEdgeDistance(start, i) <= max_range && start_point.GetLocation().Distance(GetPoint(i).GetLocation()) < max_distance) Link(i, origin, CalcEdgeDistance(origin, i)); } }
void OLCSprint::AddStartEdges() { assert(num_stages <= MAX_STAGES); assert(num_stages > 0); assert(n_points > 0); const int max_altitude = GetMaximumStartAltitude(TraceManager::GetPoint(n_points - 1)); const ScanTaskPoint start(0, FindStart()); if (GetPoint(start).GetIntegerAltitude() <= max_altitude) LinkStart(start); }
void ContestDijkstra::AddEdges(const ScanTaskPoint origin, const unsigned first_point) { ScanTaskPoint destination(origin.GetStageNumber() + 1, std::max(origin.GetPointIndex(), first_point)); const int min_altitude = IsFinal(destination) ? GetMinimumFinishAltitude(GetPoint(FindStart(origin))) : 0; if (IsFinal(destination) && first_finish_candidate > destination.GetPointIndex()) /* limit the number of finish candidates during incremental search */ destination.SetPointIndex(first_finish_candidate); const unsigned weight = GetStageWeight(origin.GetStageNumber()); bool previous_above = false; for (const ScanTaskPoint end(destination.GetStageNumber(), n_points); destination != end; destination.IncrementPointIndex()) { bool above = GetPoint(destination).GetIntegerAltitude() >= min_altitude; if (above) { const unsigned d = weight * CalcEdgeDistance(origin, destination); Link(destination, origin, d); } else if (previous_above) { /* After excessive thinning, the exact TracePoint that matches the required altitude difference may be gone, and the calculated result becomes overly pessimistic. This code path makes it optimistic, by checking if the previous point matches. */ /* TODO: interpolate the distance */ const unsigned d = weight * CalcEdgeDistance(origin, destination); Link(destination, origin, d); } previous_above = above; } if (IsFinal(destination) && predicted.IsDefined()) { const unsigned d = weight * GetPoint(origin).FlatDistanceTo(predicted); destination.SetPointIndex(predicted_index); Link(destination, origin, d); } }
void KillAllLoops() { shared_ptr<GraphSplitter<Graph>> splitter_ptr = LongEdgesExclusiveSplitter<Graph>(graph_, splitting_edge_length_); GraphSplitter<Graph> &splitter = *splitter_ptr; while(splitter.HasNext()) { set<VertexId> component_set = splitter.Next().vertices(); if(component_set.size() > max_component_size_) continue; VertexId start = FindStart(component_set); VertexId finish = FindFinish(component_set); if(start == VertexId() || finish == VertexId()) { continue; } KillLoop(start, finish, component_set); } CompressAllVertices(graph_); }
int main() { int num = 0; scanf("%d %d", &h, &w); for(int y = 0; y < h; ++y) { char str[16]; scanf("%s", str); for(int x = 0; x < w; ++x) { if(str[x] == '.') mat[y][x] = -2; // Space else { mat[y][x] = -1; // Polyomino ++num; } } } bool success = false; for(numPolys = 2; numPolys <= 5; ++numPolys) { if(num % numPolys != 0) continue; polysize = num/numPolys; if(FindStart(0,0,0)) { success = true; break; } } if(success) { for(int y = 0; y < h; ++y) { for(int x = 0; x < w; ++x) printf("%c", (mat[y][x] == -2 ? '.' : mat[y][x] + '1')); printf("\n"); } } else printf("No solution\n"); return 0; }
void WorldCursor::Setup(grip gContext) { Context *pContext; msgMask = E_MOUSE_DOWN | E_MOUSE_UP; fIsMouseDown = FALSE; // attach ourselves to context SetContext(gContext); SetRes(RES_ANIM,102,2); SetContext(gContext); SetPri(PRI_INTERFACE + 1); FindStart(); Guy::Setup(); pContext = ADerefAs(Context,gContext); pContext->CutObject(gSelf, CT_SERV); }
// convert a String to QSgml void QSgml::String2Sgml(const QString &SgmlString) { QSgmlTag *LastTag; QString sDummy; int iPos = 0; int iStart = 0,iEnd = 0; QList<QString>::iterator i; sSgmlString = SgmlString; DocTag->Children.clear(); LastTag = DocTag; do { // Handle exception-tags for( i = tagExeption.begin(); i!=tagExeption.end(); ++i ) { QString sName = *i; if( LastTag->Name.toLower()==sName ) // its an exception-tag { iPos = SgmlString.toLower().indexOf("</" + sName,iPos); iPos--; } } FindStart(SgmlString,iPos); // no new start if( iPos==-1 ) { LastTag->Children.append( EndTag ); break; } // there was CDATA else if( iPos > iEnd + 1 ) { HandleCdata(SgmlString,LastTag,iStart,iEnd,iPos); } // this is a comment if( (SgmlString.at(iPos + 1)=='!')&&(SgmlString.at(iPos + 2)=='-')&&(SgmlString.at(iPos + 3)=='-') ) { HandleComment(SgmlString,LastTag,iStart,iEnd,iPos); } // this is a PI // else if( SgmlString.at(iPos+1)=='?' ) // { // HandleDoctype(SgmlString,LastTag,iStart,iEnd,iPos); // } // this is a Doctype else if( SgmlString.at(iPos + 1)=='!' ) { HandleDoctype(SgmlString,LastTag,iStart,iEnd,iPos); } // this is an Endtag else if( SgmlString.at(iPos + 1)=='/' ) { HandleEndTag(SgmlString,LastTag,iStart,iEnd,iPos); } // this is an Starttag of Standalone else { HandleStartTag(SgmlString,LastTag,iStart,iEnd,iPos); } } while( iPos!=-1 ); }
// Finding word bounds (what'll be converted) (Str is in OEM) BOOL FindBounds(TCHAR *Str, int Len, int Pos, int &Start, int &End) { int i=1; BOOL ret = FALSE; // If line isn't empty if( Len>Start ) { End=std::min(End,Len); // Pos between [Start, End] ? Pos=std::max(Pos,Start); Pos=std::min(End,Pos); // If current character is non letter if(!MyIsAlpha(Str[Pos])) { // Looking for letter on the left and counting radius while((Start<=Pos-i) && (!MyIsAlpha(Str[Pos-i]))) i++; // Radius int r=MAXINT; // Letter was found on the left if(Start<=Pos-i) r=i; // Storing radius i=1; // Looking for letter on the right and counting radius while((Pos+i<=End) && (!MyIsAlpha(Str[Pos+i]))) i++; // Letter was not found if(Pos+i>End) i=MAXINT; // Here r is left radius and i is right radius // If no letters was found if( std::min(r,i)!=MAXINT ) { // What radius is less? Left? if( r <= i ) { End=Pos-r+1; Start=FindStart(Str, Start, End); } else // Right! { Start=Pos+i; End=FindEnd(Str, Start, End); }; ret=TRUE; }; } else // Current character is letter! { Start=FindStart(Str, Start, Pos); End=FindEnd(Str, Pos, End); ret=TRUE; }; }; if(!ret) Start=End=-1; return ret; };