贪心,Gene Assembly,ZOJ(1076)
2016-03-16 13:16
363 查看
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=76
解题报告:
1、类似活动安排问题。
2、输出格式要注意。
解题报告:
1、类似活动安排问题。
2、输出格式要注意。
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; struct gene { int s;///起始 int f;///结束 int index;///编号 } a[1005]; bool b[1005]; bool cmp(const gene&a,const gene&b) { if(a.f<=b.f) return true; else return false; } int main() { int n; while(scanf("%d",&n),n) { memset(b,false,sizeof(b)); for(int i=0; i<n; i++) { scanf("%d%d",&a[i].s,&a[i].f); a[i].index=i+1; } sort(a,a+n,cmp); b[0]=true; int PreEnd=0; for(int i=1; i<n; i++) { if(a[i].s>a[PreEnd].f) { b[i]=true; PreEnd=i; } } printf("%d",a[0].index); for(int i=1; i<n; i++) if(b[i]) printf(" %d",a[i].index); printf("\n"); } return 0; }
相关文章推荐
- 快速傅里叶(FFT)
- Web端裁剪图片方法
- 经典排序算法(9)——桶排序算法详解
- 学习进度条
- The equation 之深入理解扩展欧几里得
- cocoa touch框架UIkit学习
- linux 进程详解
- 建筑公司员工财务数据库分析
- C#动态创建类实例并调用
- 经典排序算法(8)——归并排序算法详解
- CGContextAddArcToPoint和CGContextAddArc
- HDU - 4815 Little Tiger vs. Deep Monkey (长春赛区C题)
- SYN2306C型 GPS北斗授时导航接收机
- QQ音乐与网易云音乐的比较
- linux yum 用法
- System获取时间函数代码
- Hadoop Shell 讲解
- Maven全解
- android发送短信、会话列表、短信详情
- App开发10个常用工具类