My program is to solve the simple problem in the Link[http://codeforces.com/problemset/problem/143/A]
#include <stdio.h>
#include <cstring>
#include <math.h>
#include<set>
#include<iostream>
#include<algorithm>
#define MAXN 25
#define INF 100000000
using namespace std;
struct _point
{
int L;int r;
bool operator<(const _point &a)const{
return (this->L<a.L);
}
};
set<_point> up,down;
int r1,r2,c1,c2,d1,d2;
void solve(){
_point tmp;
for(int i=0;i<(r1+1)/2;i++){
cin>>tmp.L;cin>>tmp.r; up.insert(tmp);
}
for(int i=0;i<(r2+1)/2;i++){
cin>>tmp.L>>tmp.r;down.insert(tmp);
}
set<_point>::iterator it_up=up.begin();
set<_point>::iterator it_down=down.begin();
for(it_up=up.begin();it_up!=up.end();it_up++){
//------------Problem is in the next line(it_down++)------------
for(it_down=down.begin();it_down!=down.end();it_down++){
//-------------------------------------------------------------
if((*it_up).L+(*it_down).L!=c1||(*it_up).r+(*it_down).r!=c2||(*it_up).r+(*it_down).L!=d2||(*it_up).L+(*it_down).r!=d1) {
up.erase(*it_up),down.erase(*it_down);
}
}
}
it_up=up.begin(),it_down=down.begin();
if(!up.empty()&&!down.empty()){
cout<<(*it_up).L<<" "<<(*it_down).r<<endl;
cout<<(*it_down).L<<" "<<(*it_down).r<<endl;
}
else cout<<-1<<endl;
}
int main()
{
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
while(cin>>r1>>r2>>c1>>c2>>d1>>d2) solve();
return 0;
}
Thanks for your HELP,sincerely!
New Jack
-3
Newbie Poster
Recommended Answers
Jump to PostWhat does it do that you think it shouldn't do, or what does it not do that you think it should do? You have to say more than "here is a problem".
As an aside, you're including C headers for which there are modern C++ replacement version, and some of …
Jump to PostIf I had to guess, you're changing the containers
down
andup
, and in doing so invalidating iterators.When you call erase on an iterator in a set, you invalidate that iterator.
Here's a quote from a standard, but I don't recall if this is from C++98 or C++03 or …
All 6 Replies
Moschops
683
Practically a Master Poster
Featured Poster
New Jack
-3
Newbie Poster
Moschops
683
Practically a Master Poster
Featured Poster
NathanOliver
429
Veteran Poster
Featured Poster
New Jack
-3
Newbie Poster
Moschops
683
Practically a Master Poster
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.