#include "stdio.h"
void main()
{
int act[11][3]={{1,1,4},{2,3,5},{3,0,6},{4,5,7},{6,5,9},
{7,6,10},{8,8,11},{9,8,12},{10,2,13},{11,12,14}};
greedy(act,11);
getch();
}
int greedy(int *act,int n)
{
int i,j,no;
j=0;
printf("Selected activities:/n");
no=0;
printf("Act.%2d: Start time %3d, finish time %3d/n", act[no],act[no+1],act[no+2]);
for(i=1;i<n;i++)
{
no=i*3;
if(act[no+1]>=act[j*3+2])
{
j=i;
printf("Act.%2d: Start time %3d, finish time %3d/n", act[no],act[no+1],act[no+2]);
}
}
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct join
{
int begin;
int end;
};
int compare(const void *a, const void *b);
int main()
{
int i, n, k;
struct join joins[1001], temp[1001];
while(scanf("%d", &n) != EOF)
{
for(i = 0; i < n; i ++)
{
scanf("%d %d", &joins[i].begin, &joins[i].end);
}
qsort(joins, n, sizeof(joins[0]), compare);
k = 0;
temp[k] = joins[0];
for(i = 1; i < n; i ++)
{
if(joins[i].begin >= temp[k].end)
temp[++ k] = joins[i];
}
printf("%d\n", k + 1);
}
return 0;
}
int compare(const void *a, const void *b)
{
const struct join *p = a;
const struct join *q = b;
return p->end - q->end;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有