int main(){ scanf("%d%d",&N,&Q); for(int i=0;i<N;++i){ ll a,b,c; scanf("%lld%lld%lld",&a,&b,&c); a=rev(a),b=rev(b); evts.emplace_back(st(a)+1,st(b)+1,ed(b),c); evts.emplace_back(ed(a),st(b)+1,ed(b),-c); } std::sort(all(evts)); for(int i=0;i<Q;++i){ ll a,b; scanf("%lld%lld",&a,&b); qrys.emplace_back(rev(a),rev(b),i); } std::sort(all(qrys)); int i=0; for(qry &q:qrys){ while(i<evts.size()&&evts[i].x<=q.x){ ins(rt,new nd(evts[i].y1,evts[i].v)); ins(rt,new nd(evts[i].y2,-evts[i].v)); ++i; } nd *l=0,*r=0; spt(rt,l,r,q.y); ans[q.i]=sum(l); mrg(rt,l,r); } for(int i=0;i<Q;printf("%lld\n",ans[i++])); }
int main(){ scanf("%d%d",&N,&M); for(int i=0,a;i<N;++i){ scanf("%d",&a); mrg(rt,rt,new nd(a)); } for(int i=0,a,b,c;i<M;++i){ scanf("%d%d%d",&a,&b,&c); nd *l=0,*m=0,*r=0; spt(rt,m,r,c); spt(m,l,m,b-1); if(a==1){ mrg(m,m,l); mrg(rt,m,r); }else{ mrg(m,r,m); mrg(rt,l,m); } } printf("%d\n",abs(rht(rt)-lft(rt))); dfs(rt); }
void shared_ptrExample(){ std::cout << "Shared Pointer:" << std::endl; std::list<std::shared_ptr<message>> l1; std::list<std::shared_ptr<message>> l2; std::cout << "Creamos Mensaje 1" << std::endl; std::shared_ptr<message> spt(new message("Mensaje 1")); std::cout << "Referencias del Puntero Compartido: " << spt.use_count() << std::endl; std::cout << "Añadimos Mensaje 1 al final de la lista." << std::endl; l1.push_back(spt); std::cout << "Mensaje 1 Añadido." << std::endl; std::cout << "Referencias del Puntero Compartido: " << spt.use_count() << std::endl; std::cout << "Obtenemos mensaje" << std::endl; std::shared_ptr<message> tmp2; for(auto& tmp1 : l1){ if(tmp1->getString()=="Mensaje 1"){ tmp2 = tmp1; } } std::cout << "mensaje obtenido " << tmp2->getString() << std::endl; std::cout << "Referencias del Puntero Compartido: " << tmp2.use_count() << std::endl; { std::cout << "Entramos otro Scope" << std::endl; std::shared_ptr<message> spt2(new message("Mensaje 2")); std::shared_ptr<message> spt3(new message("Mensaje 3")); std::cout << "Añadimos Mensaje 2 al frente de la lista." << std::endl; l1.push_front(spt2); std::cout << "Referencias del Puntero Compartido: " << spt2.use_count() << std::endl; std::cout << "Salimos Otro Scope" << std::endl; } std::cout << "Referencias del Puntero Compartido: " << spt.use_count() << std::endl; std::cout << "Process Function Call" << std::endl; processMessageSPTR(l1.front()); std::cout << "Process Function End" << std::endl; { std::cout << "Copy Message 2" << std::endl; std::shared_ptr<message> spt2(l1.front()); std::cout << "Borramos message 2" << std::endl; l1.erase(l1.begin()); std::cout << "Message 2 Borrado" << std::endl; std::cout << "Referencias del Puntero Compartido: " << spt2.use_count() << std::endl; std::cout << "Contenido MSG 2 " << spt2->getString() << std::endl; std::cout << "añadimos MSG2 a l2 " << std::endl; l2.push_back(spt2); std::cout << "Referencias del Puntero Compartido: " << spt.use_count() << std::endl; } std::cout << "Obtenemos Mensaje Lista 2 " << l2.front()->getString() << std::endl; std::cout << "Referencias del Puntero Compartido: " << l2.front().use_count() << std::endl; std::cout << "Salimos Programa." << std::endl; }
void BellmanFord::findNegativeCycle(){ EdgeWeightedDigraph spt(V); for(int v = 0; v < V; ++v) if(edgeTo[v].from() || edgeTo[v].to() || edgeTo[v].Getweight()) spt.addEdge(edgeTo[v].from(),edgeTo[v].to(),edgeTo[v].Getweight()); EdgeWeightedCycleFinder cf(spt); if(cf.hasCycle()){ std::deque<int> *TempCycle = cf.GetCycle(); std::deque<int>::const_iterator it; for(it = TempCycle->begin(); it != TempCycle->end();++it) cycle.push_back(*it); } }
void unique_ptrExample(){ std::cout << "Unique Pointer " << std::endl; std::list<std::unique_ptr<message>> l1; std::list<std::unique_ptr<message>> l2; std::cout << "Creamos Mensaje 1" << std::endl; std::unique_ptr<message> spt(new message("Mensaje 1")); std::cout << "Añadimos Mensaje 1 al final de la lista." << std::endl; l1.push_back(std::move(spt)); std::cout << "Mensaje 1 Añadido." << std::endl; std::cout << "Obtenemos mensaje" << std::endl; std::unique_ptr<message> tmp2; for(auto& tmp1 : l1){ if(tmp1->getString()=="Mensaje 1"){ tmp2 = std::move(tmp1); } } std::cout << "mensaje obtenido " << tmp2->getString() << std::endl; { std::cout << "Entramos otro Scope" << std::endl; std::unique_ptr<message> spt2(new message("Mensaje 2")); std::unique_ptr<message> spt3(new message("Mensaje 3")); spt2 == spt3; std::cout << "Añadimos Mensaje 2 al frente de la lista." << std::endl; l1.push_front(std::move(spt2)); std::cout << "Salimos Otro Scope" << std::endl; } std::cout << "Process Function Call" << std::endl; l1.push_front(processMessageUPTR(std::move(l1.front()))); std::cout << "Process Function End" << std::endl; { std::cout << "l1 size: " << l1.size() << std::endl; std::cout << "Move Message 2" << std::endl; std::unique_ptr<message> spt2(std::move(l1.front())); std::cout << "l1 size: " << l1.size() << std::endl; std::cout << "Borramos message 2" << std::endl; l1.pop_front(); std::cout << "l1 size: " << l1.size() << std::endl; std::cout << "Message 2 Borrado : " << std::endl; std::cout << "Contenido MSG 2 " << spt2->getString() << std::endl; std::cout << "añadimos MSG2 a l2 " << std::endl; l2.push_back(std::move(spt2)); } std::cout << "Obtenemos Mensaje Lista 2 " << l2.front()->getString() << std::endl; std::cout << "Salimos Programa." << std::endl; }
int main(int argc, char **argv) { atexit(mkl_free_buffers); Graph g = GraphLoader::fromStdin(); StarDecompositionTree spt(g, 0); printf("%d %d\n", g.nv(), g.nv() - 1); for (int i = 0; i < g.nv(); ++i) { if (i != 0) { int parent = g.neighbor(i, spt.parentIndex[i]); int u = std::min(i, parent); int v = std::max(i, parent); double w = 1.0; //spt.weight[i]; printf("%d %d %lf\n", u, v, w); } } return 0; }
void LayoutTest::testTrainer() { //cv::Mat testM(10, 10, CV_8UC1); // //for (int rIdx = 0; rIdx < testM.rows; rIdx++) { // unsigned char* ptr = testM.ptr<unsigned char>(rIdx); // for (int cIdx = 0; cIdx < testM.cols; cIdx++) { // ptr[cIdx] = cIdx*rIdx+cIdx; // } //} // //QJsonObject jo = Image::matToJson(testM); //cv::Mat t2 = Image::jsonToMat(jo); //cv::Scalar s = cv::sum(cv::abs(testM - t2)); //if (s[0] != 0) // qWarning() << "inconsistent json2Mat I/O"; //else // qInfo() << "json to mat is just fine..."; Timer dt; FeatureCollectionManager fcm = FeatureCollectionManager::read(mConfig.featureCachePath()); // train classifier SuperPixelTrainer spt(fcm); if (!spt.compute()) qCritical() << "could not train data..."; spt.write(mConfig.classifierPath()); // read back the model QSharedPointer<SuperPixelModel> model = SuperPixelModel::read(mConfig.classifierPath()); auto f = model->model(); if (f->isTrained()) qDebug() << "the classifier I loaded is trained..."; //qDebug() << fcm.numFeatures() << "SuperPixels trained in" << dt; }
void ins(nd *&n,nd *i){ if(!n)n=i; else if(i->p>n->p) spt(n,i->l,i->r,i->key),n=i; else ins(n->key<=i->key?n->r:n->l,i); upd(n); }
void spt(nd *n,nd *&l,nd *&r,ll key){ if(!n) l=r=0; else if(n->key<=key) spt(n->r,n->r,r,key),l=n; else spt(n->l,l,n->l,key),r=n; upd(n); }
void spt(nd *n,nd *&l,nd *&r,int key){ if(!n)l=r=0; else if(sz(n->l)<key)spt(n->r,n->r,r,key-sz(n->l)-1),l=n; else spt(n->l,l,n->l,key),r=n; upd(n); }
void Menu::render(sf::RenderTarget *target) { target->Clear(sf::Color(0,0,0)); sf::Sprite sp(bg); target->Draw(sp); sf::Sprite spt(title); spt.SetPosition(130, 80); target->Draw(spt); if(!onCredits) { sf::Shape sh = sf::Shape::Rectangle(290, 410, 436, 520, sf::Color(110,90,60,150), 1.f, sf::Color(30,35,60,200)); target->Draw(sh); bLvl1.render(target); bLvl2.render(target); bLvl3.render(target); bShowCredits.render(target); } else { sf::Shape sh = sf::Shape::Rectangle(210, 350, 520, 560, sf::Color(50,50,50,200), 1.f, sf::Color(30,35,60,200)); target->Draw(sh); sf::String creditText, creditTitles; creditTitles.SetPosition(225, 360); // creditTitles.SetStyle(); creditTitles.SetSize(14); creditTitles.SetColor(sf::Color(220,220,200)); creditText.SetPosition(370, 360); creditText.SetStyle(sf::String::Italic); creditText.SetSize(14); std::string str = "" "Developpement\n" "et conception:\n" "\n\n" "Musique:\n" "\n\n" "Graphismes:\n" "\n" "\n" "\n\n" "Effets sonores:\n" "\n"; creditTitles.SetText(str); std::string str2 = "" "\n" "Freddy Teuma\n" "\n\n" "Celestial Aeon Project\n" "\n\n" "Julien Venerosy,\n" "Freddy Teuma\n" "Battle for Wesnoth\n" "\n\n" "Freddy Teuma\n" "\n"; creditText.SetText(str2); target->Draw(creditTitles); target->Draw(creditText); bHideCredits.render(target); } }
/** display a time-stamped message * -- typically call with twmsg(__func__, "some msg"); * -- can use __FUNCTION__ or __PRETTY_FUNCTION__ in C * -- if using __PRETTY_FUNCTION in C++ it will include the type */ void twmsg(const char* where, const char* msg) { char* tbuf = spt(NULL); printf("%s: %s: %s\n", tbuf, where, msg); g_free(tbuf); }