标签:
Description
Input
Output
Sample Input
Sample Output
#include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) const int inf=0x7fffffff; //无限大 char op[3]; struct interval { int start,endn; bool operator < (const interval& b)const{ if(start!=b.start) return start<b.start; else return endn<b.endn; } }; interval val[20001]; void white(int a,int b,int& cnt) { val[cnt].start=a; val[cnt].endn=b; cnt++; } void black(int a,int b,int& cnt) { int tmp=cnt; for(int i=0;i<cnt;i++) { if(val[i].start<a) { if(val[i].endn>=a) { if(val[i].endn<=b) { val[i].endn=a-1; } else { val[tmp].start=b+1; val[tmp].endn=val[i].endn; tmp++; val[i].endn=a-1; } } } else if(val[i].start<=b) { if(val[i].endn<=b) { val[i].start=0; val[i].endn=-1; } else { val[i].start=b+1; } } } cnt=tmp; } int solve(int cnt,int& index) { sort(val,val+cnt); int maxn=val[0].endn-val[0].start+1; for(int i=1;i<cnt;i++) { if(val[i].start!=0) { if(val[i].start<=val[i-1].endn+1) { if(val[i-1].endn<=val[i].endn) { val[i].start=val[i-1].start; } else { val[i].start=val[i-1].start; val[i].endn=val[i-1].endn; } } if(val[i].endn-val[i].start+1>maxn) { maxn=val[i].endn-val[i].start+1; index=i; } } } return maxn; } int main() { int n,index,a,b,c; while(cin>>n) { int cnt=0; for(int i=0;i<n;i++) { scanf("%d%d%s",&a,&b,op); if(a>b) { swap(a,b); } if(op[0]==‘w‘) white(a,b,cnt); else black(a,b,cnt); } index=0; if(solve(cnt,index)) { cout<<val[index].start<<" "<<val[index].endn<<endl; } else cout<<"Oh, my god"<<endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/qscqesze/p/4245727.html