时间限制:3000 ms  |  内存限制:65535 KB
难度:4
 
描述
学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办。小刘的工作就是安排学校小礼堂的活动,每个时间最多安排一个活动。现在小刘有一些活动计划的时间表,他想尽可能的安排更多的活动,请问他该如何安排。
 
输入
第一行是一个整型数m(m<100)表示共有m组测试数据。
每组测试数据的第一行是一个整数n(1<n<10000)表示该测试数据共有n个活动。
随后的n行,每行有两个正整数Bi,Ei(0<=Bi,Ei<10000),分别表示第i个活动的起始与结束时间(Bi<=Ei)
输出
对于每一组输入,输出最多能够安排的活动数量。
每组的输出占一行
样例输入
2
2
1 10
10 11
3
1 10
10 11
11 20
样例输出
1
2
提示
注意:如果上一个活动在t时间结束,下一个活动最早应该在t+1时间开始
 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef struct act{
int s;
int e;
}STACT;
int compare(const void *a, const void *b){
STACT *acts1 = (STACT *)a;
STACT *acts2 = (STACT *)b;
return (acts1->e - acts2->e);
}
int main()
{
//m:num of test,n:num of activities
int m,n;
int i;
scanf("%d", &m);
getchar();
while (m--) {
scanf("%d", &n);
getchar();
STACT *ats=(STACT *)malloc(sizeof(STACT)*n);
memset(ats, 0x00, sizeof(STACT)*n);
for (i = ; i < n; ++i) {
scanf("%d%d", &ats[i].s, &ats[i].e);
}
qsort(ats, n, sizeof(ats[]), compare);
int sum=;
int curTime=-;
for (i = ; i < n; ++i) {
if(curTime < ats[i].s){
++sum;
curTime = ats[i].e;
}
else {
continue;
}
}
printf("%d\n", sum);
if(ats != NULL){
free(ats);
ats=NULL;
}
}
return ;
}

Time: 172ms Space:316

 #include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct act{
int s;
int e;
}actnode[];
int compare(const void *a, const void *b){
act *acts1 = (act *)a;
act *acts2 = (act *)b;
return (acts1->e - acts2->e);
}
int main()
{
//m:num of test,n:num of activities
int m,n;
int i;
scanf("%d", &m);
getchar();
while (m--) {
scanf("%d", &n);
getchar(); memset(&actnode , 0x00, sizeof(actnode));
for (i = ; i < n; ++i) {
scanf("%d%d", &actnode[i].s, &actnode[i].e);
}
qsort(actnode, n, sizeof(actnode[]), compare);
int sum=;
int curTime=-;
for (i = ; i < n; ++i) {
if(curTime < actnode[i].s){
++sum;
curTime = actnode[i].e;
}
else {
continue;
}
}
printf("%d\n", sum); }
return ;
}

212ms 392

 选择结束时间最早的,贪心算法

解体思路

有误:

 #include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define debug(x) cout << #x << " at line " << __LINE__ << " is: " << x << endl struct noac{
int Ti_s;
int Ti_e;
bool operator<(const noac& nc) const // DESC by Ti_s
{
return (Ti_s > nc.Ti_s);
}
friend void operator<<(ostream &os, const noac &nc)
{
os << nc.Ti_s << ' ' << nc.Ti_e << endl;
}
}tms[]; int main(){
int m,n;
scanf("%d", &m);
while (m--) {
scanf("%d", &n);
memset(&tms, , 0x00);
for (int i = ; i < n; ++i)
{
scanf("%d%d", &tms[i].Ti_s, &tms[i].Ti_e);
}
sort(tms, tms + n); int maxac = ;
for (int i = ; i < n; ++i)
{
int idx = i;
int sum = ;
for (int j = i+; j < n; ++j)
{
if(tms[idx].Ti_s >= tms[j].Ti_e)
{
++sum;
++idx;
}else
{
continue;
}
}
maxac = max(maxac, sum);
}
printf("%d\n", maxac);
}
return ;
}

比如说:

6
1 5
2 3
10 11
6 7
8 9
4 5

output: 4,而实际输出为5

14.会场安排问题(L4)的更多相关文章

  1. nyoj 14 会场安排问题(贪心专题)java

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  2. nyoj 14 会场安排问题(贪心专题)

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  3. nyoj 14 会场安排问题

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  4. NYOJ 14 会场安排问题(也算是经典问题了)

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4 描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工作就 ...

  5. nyoj 题目14 会场安排问题

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  6. 基于贪心算法的几类区间覆盖问题 nyoj 12喷水装置(二) nyoj 14会场安排问题

    1)区间完全覆盖问题 问题描述:给定一个长度为m的区间,再给出n条线段的起点和终点(注意这里是闭区间),求最少使用多少条线段可以将整个区间完全覆盖 样例: 区间长度8,可选的覆盖线段[2,6],[1, ...

  7. 会场安排问题--nyoj题目14

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  8. ACM 会场安排问题

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...

  9. NYOJ 14 场地安排

    /* 中国标题的含义: 中国的翻译: 标题效果:寻求预定场地的最大数量,只有一个活动可以安排时间 解决问题的思路:然后使用结构数.之后再构建一个排序,排序结束时间活动.然后基于开始时间为大于一个事件的 ...

随机推荐

  1. POJ 3041&&3020

    两道二分图的练手题. 3041:题意大概是在一个N*N的图上有K个东西,你每次可以清除一行或一列上的所有东西.让你求最少的操作次数. 我们根据题意建图.对于每一个点的坐标(x,y)之间连一条边.比如样 ...

  2. SpringBoot配置Aop笔记【例子】

    众所周知,spring最核心的两个功能是aop和ioc,即面向切面,控制反转.这里我们探讨一下如何使用spring aop. 1.何为aop aop全称Aspect Oriented Programm ...

  3. python3面向对象注意事项

    一.面向对象super的作用: class parent(object): def __init__(self): self.test() def test(self): print('parent- ...

  4. Python_Xlrd&Xlwt

    import xlrd # \U 开始的字符被编译器认为是八进制 解决方法 r objWB = xlrd.open_workbook(r'C:\Users\IBM\Desktop\S1\7月下旬入库表 ...

  5. 论文阅读 | Clustrophile 2: Guided Visual Clustering Analysis

    论文地址 论文视频 左侧边栏可以导入数据,或者打开以及前保存的结果.右侧显示了所有的日志,可以轻松回到之前的状态,视图的主区域上半部分是数据,下半部分是聚类视图. INTRODUCTION 数据聚类对 ...

  6. Spherical Hashing,球哈希

    1. Introduction 在传统的LSH.SSH.PCA-ITQ等哈希算法中,本质都是利用超平面对数据点进行划分,但是在D维空间中,至少需要D+1个超平面才能形成一个封闭.紧凑的区域.而球哈希方 ...

  7. 从零开始学Kotlin-类和对象(5)

    定义一个类 定义一个类,使用关键字class声明,后面跟类名(不使用new) class demo5 {//定义一个类,使用关键字class声明,后面跟类名 fun test() {//类中定义方法 ...

  8. week3 团队博客作业

    团队自我介绍地址: http://www.cnblogs.com/liuliudashun/p/5919555.html

  9. 如何运行spring项目,并打成jar包进行发布

    一.创建spring项目 1.创建项目 2.创建moudule,选择java类型即可. 3.创建lib文件,引入spring的4个核心包spring-beans.spring-context.spri ...

  10. Postgresql迁移数据文件存放位置

    1. POSTGRESQL的安装 centos7 里面默认的pgsql的版本是 如果想用更高的版本需要执行以下如下的命令 rpm -ivh https://download.postgresql.or ...