xtrm0 Posted April 29, 2012 at 07:22 PM Report #452088 Posted April 29, 2012 at 07:22 PM Boas, nao consigo encontar o erro. O que é que esta mal na linha do for? vector <pair <int, int> > intrvls; /* ... */ list<pair <int, int> > nintr(intrvls.begin(), intrvls.end()); for (list<pair <int, int> >::iterator it = nintr.begin(); (it+1) != nintr.end(); it++) if ((*(it+1)).first <= (*it).second) { it->second = std::max(it->second, (*(it+1)).second); nintr.erase(it+1); } } Cumprimentos, Xtrm0 <Signature goes here>
Localhost Posted April 29, 2012 at 07:37 PM Report #452095 Posted April 29, 2012 at 07:37 PM Eu não curto C++ mas convém colocares o erro para o pessoal tentar ver... here since 2009
xtrm0 Posted April 29, 2012 at 08:09 PM Author Report #452104 Posted April 29, 2012 at 08:09 PM Nao estou agora no pc, mas era um erro que aparecia repetido nestas linhas: for (list<pair <int, int> >::iterator it = nintr.begin(); (it+1) != nintr.end(); it++) if ((*(it+1)).first <= (*it).second) { it->second = std::max(it->second, (*(it+1)).second); nintr.erase(it+1); E que tinha qualquer coisa a ver com o iterator. <Signature goes here>
xtrm0 Posted April 29, 2012 at 08:10 PM Author Report #452105 Posted April 29, 2012 at 08:10 PM Btw, hahahahahaha o Benfica empatou. 😁😄 :D <Signature goes here>
Localhost Posted April 29, 2012 at 08:14 PM Report #452107 Posted April 29, 2012 at 08:14 PM Btw, hahahahahaha o Benfica empatou. 😁😄 :D -.- here since 2009
pikax Posted April 29, 2012 at 08:26 PM Report #452109 Posted April 29, 2012 at 08:26 PM Btw, hahahahahaha o Benfica empatou. 😁😄 :D -.-' O erro, e' por causa do (it+1). error: no match for 'operator+' in 'it + 1' for (list<pair <int, int> >::iterator it = nintr.begin(); it != nintr.end(); ++it) usa o pre-increment em vez do post-increment. Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
xtrm0 Posted April 29, 2012 at 08:32 PM Author Report #452111 Posted April 29, 2012 at 08:32 PM Ok. Obrigado, e como e que substituo para ter o mesmo efeito que tinha anteriormente? Nao da para se usar o it como se fosse um ponteiro normal? <Signature goes here>
pikax Posted April 29, 2012 at 08:38 PM Report #452112 Posted April 29, 2012 at 08:38 PM podes criar 2 iterators um com uma posicao a frente do outro. EDIT: Os iterator serve so' para fazer pesquisa pelos os containers, mais info Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
xtrm0 Posted April 29, 2012 at 08:42 PM Author Report #452113 Posted April 29, 2012 at 08:42 PM E como e que atualizo quando faço o erase? E só preciso atualizar o (it+1) ou e preciso atualizar o (it) também? <Signature goes here>
pikax Posted April 29, 2012 at 08:49 PM Report #452115 Posted April 29, 2012 at 08:49 PM Isso e' consoante o teu codigo, pelo o que percebi deve ser algo assim: vector <pair <int, int> > intrvls; /* ... */ list<pair <int, int> > nintr(intrvls.begin(), intrvls.end()); list<pair <int, int> >::iterator it_1=nintr.begin(); it_1++;//para ficar com o valor (it+1) for (list<pair <int, int> >::iterator it = nintr.begin(); it_1 != nintr.end(); it++) if ((*it_1).first <= (*it).second) { it->second = std::max(it->second, (*it_1).second); nintr.erase(it_1); } } Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
skiller10 Posted April 29, 2012 at 08:55 PM Report #452116 Posted April 29, 2012 at 08:55 PM Problema A da qualificação? 😄 "Eu acredito que a vida está constantemente nos testando em nosso nível de confiança, e a vida tem grande recompensa reservada àqueles que demonstram uma confiança sem fim para agir até conseguir. Este nível de resolução pode mover montanhas, mas ele tem de ser constante e consistente. Tão simples quanto isso possa soar, ainda é o denominador comum que separa aqueles que vivem seus sonhos dos que vivem simplesmente.."
xtrm0 Posted April 29, 2012 at 08:56 PM Author Report #452117 Posted April 29, 2012 at 08:56 PM Ok. Obrigado. Ah e: Btw, hahahahahaha o Benfica empatou. 😁😄 :D -.-' Fica para o ano. 😛 Problema A da qualificação? 🙂 Sim. 🙂 <Signature goes here>
skiller10 Posted April 29, 2012 at 09:00 PM Report #452119 Posted April 29, 2012 at 09:00 PM 1º - Porque não um array utilizas um array normal? 2º - Com o input abaixo o que vai gerar o teu programa? é o que é suposto gerar? Input: 3 1 6 2 3 4 10 "Eu acredito que a vida está constantemente nos testando em nosso nível de confiança, e a vida tem grande recompensa reservada àqueles que demonstram uma confiança sem fim para agir até conseguir. Este nível de resolução pode mover montanhas, mas ele tem de ser constante e consistente. Tão simples quanto isso possa soar, ainda é o denominador comum que separa aqueles que vivem seus sonhos dos que vivem simplesmente.."
pikax Posted April 29, 2012 at 09:02 PM Report #452120 Posted April 29, 2012 at 09:02 PM Fica para o ano. 😄 Nem digas nada ? porque que copias o conteudo do vector para a lista, nao podias fazer a pesquisa no vector?? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
xtrm0 Posted April 29, 2012 at 09:05 PM Author Report #452121 Posted April 29, 2012 at 09:05 PM Nao, porque depois o erase dava complexidade O(N), em vez de O(1). Depois acabei por fazer a mesma solucao sem erase nem list, mas fiquei com a duvida de qual era o meu erro. <Signature goes here>
pikax Posted April 29, 2012 at 09:07 PM Report #452122 Posted April 29, 2012 at 09:07 PM nao percebeste porque que o programa estava a dar erro na compilacao? Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
xtrm0 Posted April 29, 2012 at 09:09 PM Author Report #452123 Posted April 29, 2012 at 09:09 PM 1º - Porque não um array utilizas um array normal? 2º - Com o input abaixo o que vai gerar o teu programa? é o que é suposto gerar? Input: 3 1 6 2 3 4 10 Eu sei, eu só cortei para aqui as linhas da solucao onde dava erro. Falta o it--. <Signature goes here>
xtrm0 Posted April 29, 2012 at 09:09 PM Author Report #452124 Posted April 29, 2012 at 09:09 PM nao percebeste porque que o programa estava a dar erro na compilacao? Sim. <Signature goes here>
pikax Posted April 29, 2012 at 09:14 PM Report #452126 Posted April 29, 2012 at 09:14 PM Muito basicamente o list::iterator nao suporta o operador+. O iterator da lista e' bidirecional, so soporta estas operacoes http://www.cplusplus.com/reference/std/iterator/BidirectionalIterator/'>http://www.cplusplus.com/reference/std/iterator/BidirectionalIterator/ Os iterator que existem estao aqui: http://www.cplusplus.com/reference/std/iterator/ Por muito mais que que estude só aprendo uma coisa, que ainda tenho muita coisa para aprender. A beleza de um código está em decompor problemas complexos em pequenos blocos simples. "learn how to do it manually first, then use the wizzy tool to save time." "Kill the baby, don't be afraid of starting all over again. Fail soon, learn fast."
xtrm0 Posted April 29, 2012 at 09:24 PM Author Report #452131 Posted April 29, 2012 at 09:24 PM Ah ok. Obrigado. Da para se fazer overload para conseguir? <Signature goes here>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now