vector<int> findOrder(int numCourses, vector<pair<int, int>>& prerequisites) { vector<vector<int>> AdjList(numCourses,vector<int>()); vector<int> inDeg(numCourses,0); vector<int> ans; for(int i = 0; i < prerequisites.size(); ++i){ AdjList[prerequisites[i].second].push_back(prerequisites[i].first); inDeg[prerequisites[i].first]++; } for(int i = 0; i < numCourses; ++i){ int idx = -1; for(int j = 0; j < numCourses; ++j){ if(inDeg[j] == 0){ ans.push_back(j); idx = j; inDeg[j] = -1; break; } } if(idx != -1){ for(int v = 0; v < AdjList[idx].size(); ++v){ inDeg[AdjList[idx][v]]--; } } } return ans.size() != numCourses?vector<int>():ans; }
/// Return the detector center angle. double LoadILLReflectometry::detectorAngle() const { if (m_instrument != Supported::Figaro) { return doubleFromRun(m_detectorAngleName); } const double DH1Y = inMeter(doubleFromRun("DH1.value")); const double DH2Y = inMeter(doubleFromRun("DH2.value")); return inDeg(std::atan2(DH2Y - DH1Y, Figaro::DH2Z - Figaro::DH1Z)); }
/** Calculate the offset angle between detector center and peak. * @param peakCentre peak centre in pixels. * @param detectorCentre detector centre in pixels. * @param detectorDistance detector-sample distance in meters. * @return the offset angle. */ double LoadILLReflectometry::offsetAngle(const double peakCentre, const double detectorCentre, const double detectorDistance) const { // Sign depends on the definition of detector angle and which way // spectrum numbers increase. const auto sign = m_instrument == Supported::D17 ? 1. : -1.; const double offsetWidth = (detectorCentre - peakCentre) * m_pixelWidth; return sign * inDeg(std::atan2(offsetWidth, detectorDistance)); }
bool IdentifyLiaisonTunnel::doILT4( EdgeArray& edges ) { if( !isInitNetworkOk() ) return false; if( airEdges.isEmpty() ) return false; NodeFilter nf( dg, true ); BuildNodeFilter( dg, airEdges, sn, tn, nf ); IntMap imap( dg ); Init_IMap( dg, ef, nf, airEdges, imap ); // 记录节点的入度和出度 // 过滤阻断分支 IntMap inDeg( dg ), outDeg( dg ); InitDegMap( dg, ef, inDeg, outDeg ); bool bQuit = false; while( !bQuit ) { bQuit = true; for( Digraph::ArcIt e( dg ); e != INVALID; ++e ) { if( !ef[e] || datas[e]->et == ET_VIRTUAL ) continue; Digraph::Node u = dg.source( e ); Digraph::Node v = dg.target( e ); if( imap[u]*imap[v] <= 0 ) continue; if( outDeg[u] - 1 <= 0 || inDeg[v] - 1 <= 0 ) continue; if( imap[v] < 0 ) { bool ret = false; // 回风区,考察节点的入边是否有新风流入 for( Digraph::InArcIt ie( dg, v ); ie != INVALID; ++ie ) { if( imap[dg.source( ie )] > 0 ) { ret = true; break; } } if( ret ) continue; } outDeg[u] = outDeg[u] - 1; inDeg[v] = inDeg[v] - 1; edges.append( e ); bQuit = false; } } return true; }