贪心算法的活动安排问题代码

时间:2022-12-20 11:05:26 阅读: 最新文章 文档下载
说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。


#include using namespace std;

#define SIZE 11 //控制活动总数量的大小 typedef int Type;

void GreedySelector(int n,Type s[],Type f[],bool A[]) {

A[0]=true; int j=0;

for(int i=1;i{

if(s[i]>=f[j]) {

A[i]=true; j=i; }

else A[i]=false; } }

void main() {

int t=0;

Type s[SIZE]; Type f[SIZE];

cout<<"请输入开始时间:"<for(int z=0;zcin>>s[z];

cout<<"请输入结束时间:"<for(int j=0;jcin>>f[j];

bool re[SIZE];

GreedySelector(SIZE,s,f,re);

//cout<可安排的活动区间为:"<

for(int i=0;i{

if(re[i]) {






// cout<<(i+1)<<" "; cout<<"可安排开始时间为: "< 结束时间为: "<<<" 的活动"< t++; } }

//cout<<""<<"活动"; cout<

cout<<"总共可以安排"<个活动。"< }




本文来源:https://www.wddqw.com/doc/d710103a4731b90d6c85ec3a87c24028915f8567.html