ZOJ 1076 Gene Assembly 贪心
来源:互联网 发布:linux服务器关机命令 编辑:程序博客网 时间:2024/06/05 04:00
这道题感觉最难的就是看你题意怎么理解了。。。
在经过多次百度之后,终于理解了,题意。。
抽象出来就是给你几组数组,每组数字都代表了开始和结束,现在让你计算在开始时间到结束时间最多可以包含几组这样的数字,并且输出他们的编号(输入的顺序)
一个贪心解决,对结束时间,进行升序排列。优先选择最先结束的,这样就可以选的最多。
代码如下:
#include <iostream>#include <cstdio>#include <vector>#include <algorithm>using namespace std;const int N = 50005;struct info{ int start, end; int id;};info date[N];int n;bool cmp(const info &a, const info &b){ return a.end < b.end;}int main(){ int n; while (scanf("%d", &n) && n) { for (int i = 0; i < n; i++) { scanf("%d%d", &date[i].start, &date[i].end); date[i].id = i+1; } sort(date, date+n, cmp); vector<int> markans; markans.push_back(0); for (int i = 1; i < n; i++) { if (date[ markans[markans.size()-1] ].end <= date[i].start) markans.push_back(i); } for (int i = 0; i < markans.size()-1; i++) cout << date[markans[i]].id << " "; cout << date[ markans[markans.size()-1] ].id << endl; } return 0;}
0 0
- ZOJ 1076 Gene Assembly 贪心
- ZOJ 1076 Gene Assembly(贪心算法)
- zoj 1076 Gene Assembly
- ZOJ 1076 Gene Assembly
- zoj - 1076 - Gene Assembly
- zoj 1076 Gene Assembly
- ZOJ-1076 Gene Assembly
- Zoj 1076 Gene Assembly
- zoj 1076 Gene Assembly
- zoj 1076 Gene Assembly
- ZOJ 1076 Gene Assembly
- ZOJ 1076Gene Assembly(很简单的贪心)
- ZOJ 1076 Gene Assembly (贪心求区间不相交问题)
- ZOJ 1076 Gene Assembly(LIS)
- ZOJ 1076 Gene Assembly LIS
- zoj 1076 Gene Assembly 解题报告
- ZOJ Problem Set - 1076 Gene Assembly
- Gene Assembly(贪心,简单)
- xcode armv6 armv7 armv7s arm64
- P51页 第三题
- 新旅程的开始
- Maven+SpringMVC+MyBatis整合
- Android 创建事件监听
- ZOJ 1076 Gene Assembly 贪心
- iOS开发之-指针小结
- 一篇不错的Python入门教程
- P51 第四题
- 多线程下的同步工具--CountDownLatch
- rest 的java实现
- 配置了vim
- 斐波那契数(JAVA实现)
- Zend Studio 安装Aptana插件 (html,css,js代码提示功能)