阿里巴巴2017校招C++岗位在线编程题-RNA嵌套
来源:互联网 发布:网络维护工具app 编辑:程序博客网 时间:2024/06/08 11:28
思路
对每一个二段式集合挨个遍历,比较嵌套的二段式集合的嵌套深度即可。
#include <iostream>#include <sstream>#include <string>#include <vector>#include <deque>#include <cassert>#include <map>#include <algorithm>using namespace std;class Interval{public: explicit Interval(size_t left, size_t right) : mLeft(left), mRight(right) { assert(left <= right); } size_t left() const { return mLeft; } size_t right() const { return mRight; } /////添加 Interval(){}; Interval(const Interval &a); Interval &operator = (const Interval &a); ////private: size_t mLeft; size_t mRight;};//////Interval::Interval(const Interval &a){ this->mLeft = a.mLeft; this->mRight = a.mRight;}Interval &Interval::operator =(const Interval &a){ this->mLeft = a.mLeft; this->mRight = a.mRight; return *this;}/////inline bool operator<(const Interval& a, const Interval& b){ return a.right() < b.left();}class TwoInterval{public: explicit TwoInterval(const Interval& left, const Interval& right) : mLeft(left), mRight(right) { assert(left < right); } const Interval& left() const { return mLeft; } const Interval& right() const { return mRight; } /////添加 TwoInterval(){}; TwoInterval(const TwoInterval &a); TwoInterval &operator = (const TwoInterval &a); ////private: Interval mLeft; Interval mRight;};//////TwoInterval::TwoInterval(const TwoInterval &a){ this->mLeft = a.mLeft; this->mRight = a.mRight;}TwoInterval &TwoInterval::operator=(const TwoInterval &a){ this->mLeft = a.mLeft; this->mRight = a.mRight; return *this;}/////inline bool within(const TwoInterval& a, const TwoInterval& b){ return b.left() < a.left() && a.right() < b.right();}void input(vector<TwoInterval>& twos){ int m = 0; { string s; getline(cin, s); istringstream is(s); is >> m; } for (int i = 0; i < m; ++i) { string s; getline(cin, s); istringstream is(s); size_t a, b, c, d; is >> a >> b >> c >> d; Interval left(a, b); Interval right(c, d); twos.emplace_back(left, right); }}/////********************************////int intussusception(vector<TwoInterval>& two2){ vector<TwoInterval> result; int len = two2.size(); if (len < 2) return len; int resultNum = 0; for (int k = 0; k < len; k++) { result.push_back(two2[k]); for (int i = 1; i < len; i++) { int result_size = result.size(); for (int j = 0; j < result_size; j++) { if (within(two2[i], result[j])) { if (j == (result_size-1)) { result.push_back(two2[i]); } else { continue; } } if(within(result[j],two2[i])) { result.insert(result.begin()+j,two2[i]); } } } if (resultNum < result.size()) { resultNum = result.size(); } result.clear(); } return resultNum;}// ====== 结束 ========int main() { vector<TwoInterval> twos; input(twos); cout << intussusception(twos) << endl; return 0;}
阅读全文
1 0
- 阿里巴巴2017校招C++岗位在线编程题-RNA嵌套
- 阿里巴巴2017校招C++岗位在线编程题-求集合D的最大值,最小值和元素个数三者之和
- 2014阿里巴巴校招在线笔试题(数据研发工程师岗位)之二叉树
- 阿里巴巴2015秋季校招(客户端开发工程师岗位)在线笔试题
- 2017 8.25 阿里巴巴校招 在线笔试题
- 2015阿里巴巴校招在线笔试题
- 2015阿里巴巴校招在线笔试题
- 阿里巴巴2018校招编程测试题
- 2016年阿里巴巴校招笔试题(客户端开发岗位)
- 阿里巴巴2016年-校招-实习生岗位-内推
- 2015届阿里巴巴校招研发在线笔试题
- 2015年阿里巴巴校招在线笔试题
- 阿里巴巴2015校招研发在线笔试题
- 2015阿里巴巴秋招在线笔试题
- 2014 阿里校招研发岗位在线笔试题+附加题
- 海康2017校招C++开发岗位笔试题
- 阿里巴巴2018秋招在线编程测验--射击场
- 2017腾讯校招在线编程----编码
- Hexo入门学习(一):安装
- 学习css1
- HttpClient设置请求头模拟浏览器
- 弹出层layer的使用
- 充电IC-DPM(以BQS24259为例子)(动态电源管理)
- 阿里巴巴2017校招C++岗位在线编程题-RNA嵌套
- js获得url中的参数,获取当前时间
- 翻转链表
- hdu 1059 Dividing
- 第9章缓动动画
- C语言打印1000内的完数
- 解决mybatis的SELECT command denied to user 'root'@'192.168.1.47' for table 'user'的报错。mysql用户权限修改,表权限修改。
- 网络TCP建立连接为什么需要三次握手而结束要四次
- 常用排序算法-冒泡排序