栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 2301 Color the Ball

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 2301 Color the Ball

#include <iostream>#include <cstdio>#include <cstring>#include <vector>#include <set> #include <algorithm>using namespace std;class line{ public: int l,r,c; line(int l,int r,int c){ this->l = l; this->r = r; this->c = c; }};set<int> s;vector<line> vec;int n;void init(){ s.clear(); vec.clear();}bool check(int l,int r){ int c = 1; for(int i = 0 ; i < vec.size() ; i++){ if(l >= vec[i].l && r <= vec[i].r) c = vec[i].c;  } if(c == 0) return true; else return false;}int main(){ while(scanf("%d",&n)!= EOF ){ init(); int l,r,c; char cc; while(n--){ cin >> l >> r >> cc; c = (cc == 'b'? 1 : 0); vec.push_back(line(l-1,r,c)); s.insert(l-1); s.insert(r); } int ma = -1; int tmp = 0; bool con = false; int last = -1; for(set<int>::iterator it = s.begin() ; it != s.end() ; it++){ int l = *it; it++; if(it == s.end()){ it--;break; } int r = *it; it--; if(check(l,r)){ con = true; tmp += (r - l); if(tmp > ma){ ma = tmp; last = r; } } else{ con = false; tmp = 0; } } if(ma == -1) puts("Oh, my god"); else printf("%d %dn",last - ma + 1 ,last); } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379094.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号