选择不相交区间
来源:互联网 发布:上海大数据产业联盟 编辑:程序博客网 时间:2024/05/29 02:38
贪心思想
根据每个区间的结束点进行排序,然后进行更新
#include <iostream>#include <algorithm>using namespace std;struct Point{ int x, y; bool operator<(const Point s) const { return y < s.y; }}A[1002];int main() { int t,n,cnt,end; cin >> t; while (t--) { cnt = 0; end = -1; cin >> n; for (int i = 0; i < n; i++) cin >> A[i].x >> A[i].y; sort(A, A + n); for (int i = 0; i < n; i++) { if (end < A[i].x)//如果下一个区间起始点比上一个区间终点大则更新 { cnt++; end = A[i].y; } } cout << cnt << endl; } return 0;}
阅读全文
0 0
- 选择不相交区间
- 选择不相交区间
- 选择不相交区间
- 选择不相交区间
- 选择不相交区间【贪心】
- 选择不相交区间 小结
- NYOJ_996_选择不相交区间
- 选择不相交区间(贪心)
- 8.4.4(选择不相交的区间)
- 选择尽可能多的不相交区间
- 贪心法 1230选择不相交区间
- nyoj-966-选择不相交区间
- 南阳 966 选择不相交区间
- 选择不相交区间-java实现
- nyoj 966 选择不相交区间
- 南阳理工966 选择不相交区间
- 小白书贪心之选择不相交区间
- 选择不相交区间,结构体排序
- php返回上一级
- 欢迎使用CSDN-markdown编辑器
- 《 中国式思维》曾仕强读书笔记
- 用 Python 进行贝叶斯模型建模 (0)
- C#属性访问器
- 选择不相交区间
- AndroidManifest官方文档
- SpringBoot启动服务的三种方式
- Caffe学习-手写数字识别
- HDU 6029 Graph Theory【水题】
- 文章标题
- ubuntu下sublime安装
- STM8S_008_WDG独立看门狗和窗口看门狗
- 【数据挖掘】【笔记】之sklearn.ensemble