博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
贪心算法,今年暑假不AC
阅读量:7035 次
发布时间:2019-06-28

本文共 764 字,大约阅读时间需要 2 分钟。

题目链接:

活动安排问题,可用贪心。

1、把活动按结束时间递增排序。

2、直观上,选择相对活动为未安排活动留下尽可能多的时间。

#include 
#include
#include
using namespace std;struct action{ int s;///开始时间 int f;///结束时间 int index;///活动标号};action a[105];bool b[105];bool cmp(const action &a,const action &b){ if(a.f<=b.f) return true; else return false;}void GreedySelector(int n,action a[],bool b[]){ b[0]=true;///第一个活动必须选 ///记录最近一次加入到集合b中的活动 int preEnd=0; for(int i=1; i
=a[preEnd].f) { b[i]=true; preEnd=i; } }}int main(){ int n; while(scanf("%d",&n),n) { memset(b,false,sizeof(b)); for(int i=0; i

 

转载于:https://www.cnblogs.com/TreeDream/p/5271543.html

你可能感兴趣的文章
.net动态调用wsdl soap提交
查看>>
constructor&object 的联系与对比
查看>>
SEO基础问题:12.关于外链你知道多少?
查看>>
VMware安装win7:units specified don't exist问题
查看>>
软件规格说明书文档要求
查看>>
CodeForces 618A Slime Combining
查看>>
关于String的两种赋值方式
查看>>
0422-团队项目开发
查看>>
[Android Security] 如何把java代码转换成smali代码
查看>>
[Web 前端] superagent-nodejs处理请求的模块
查看>>
LA 5844 Leet (dfs 搜索)
查看>>
[USACO08NOV]时间管理Time Management
查看>>
AngularJS学习记录
查看>>
spring mvc controller间跳转 重定向 传参
查看>>
图例实解:C++中类的继承特性
查看>>
ReactiveCocoa + MVVM
查看>>
JavaScript基础知识-正则表达式
查看>>
Skia构建系统与编译脚本分析
查看>>
浅谈cocos2dx(17) 中单例管理模式
查看>>
PyTorch自动微分基本原理
查看>>