Skip to content

Instantly share code, notes, and snippets.

@anisaraf
Created October 3, 2010 02:36
Show Gist options
  • Save anisaraf/608208 to your computer and use it in GitHub Desktop.
Save anisaraf/608208 to your computer and use it in GitHub Desktop.
int PenLift::numTimes(vector<string> segments, int n)
{
transform(segments.begin(), segments.end(),
back_inserter(m_inLines), PenLift::getLine);
mergeLines();
intersectLines();
createGraph();
vector< Graph<Point> > g = m_graph.getConnectedGraphs();
if(n % 2 == 0)
return (g.size() - 1);
int rValue =0;
for( vector< Graph<Point> >::iterator it = g.begin() ;
it != g.end(); ++it)
{
int odd = it->numOddVertices()/2;
rValue += odd > 0 ? odd:1;
}
return rValue - 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment