|
|
back to boardCommon BoardHow can I avoid CE . My ASCII C++(I hope) could be copiled here but on VC 6.0 && gcc 2.95 compiled without problem..What compiler is used here.See example.Thanks. Posted by sasha 11 Sep 2003 20:01 #include <iostream> #include <map> using namespace std; typedef map<int,char> tmap; tmap line; /* ostream & operator << (ostream & out,const pair<int,char > & what) { out<<what.first<<" "<<what.second<<endl; return out; } void debug() { cout<<"***********\n"; copy(line.begin(),line.end(),ostream_iterator<pair<int,char> >(cout) ); cout<<"***********\n"; } */ char anty(char col) { return col=='w'?'b':'w'; } void insert(int left,int right,char color) { //debug(); bool left_should,right_should; tmap::iterator left_it,right_it; left_it=line.lower_bound(left); left_should=(left_it==line.begin())||((*--left_it).second!=color); right_it=line.upper_bound(right); right_should=(right_it==line.end())||((*--right_it).second!=color) ; line.erase(line.lower_bound(left),line.upper_bound(right)); if(left_should)line.insert(pair<int,char>(left,color)); if(right_should)line.insert(pair<int,char>(right,anty(color))); } void print() { int max_len=0; int max_right; int max_left; //debug(); tmap::iterator it; for(it=line.begin();it!=line.end();++it) if((*it).second=='w') { tmap::iterator it2=it; int left_cur; int right_cur; ++it2; assert(it2!=line.end()); left_cur=(*it).first; right_cur=(*it2).first-1; if(right_cur-left_cur+1>max_len) { max_len=right_cur-left_cur; max_right=right_cur; max_left=left_cur; }; } cout<<max_left<<" "<<max_right; } int main() { int i,n; cin>>n; line.insert(pair<int,char>(0,'w')); line.insert(pair<int,char>(1000000000,'b')); for(i=0;i<n;i++) { char color; int left,right; cin>>left>>right>>color; if(left>right)swap(left,right); if(left==right)continue; assert(color=='b'||color=='w'); insert(left,right,color); } print(); return 0; } |
|
|