qq_35148303 2017-06-03 08:26 采纳率: 0%
浏览 1078

一道acm题,会场安排,总是wrong answer,求助啊

Problem description
假设要在足够多的会场里安排一批活动,并希望使用尽可能少的会场。

Input
第一行有1 个正整数k,表示有 k个待安排的活动。接下来的k行中,每行有 2个正整数,分别表示 k个待安排的活动开始时间和结束时间。时间以0点开始的分钟计。 (k < 10000)

Output
将编程计算出的最少会场数输出。

Sample Input
5
1 23
12 28
25 35
27 80
36 50

Sample Output
3

代码
#include
using namespace std;

int main()
{
int n;
cin >> n;
if(n {
int *Start = new int[n];
int *End = new int[n];
bool *had = new bool[n];
for(int i=0;i {
cin>>Start[i]>>End[i];
had[i]=0;
if(Start[i]<0||End[i]<=Start[i])
{return 0;}
}

//排序
for (int i = 0; i < n; i++)
{
    for (int j = i + 1; j < n; j++)
    {
        if (End[i]>End[j])
        {
            int temp = End[j];
            End[j] = End[i];
            End[i] = temp;
            temp = Start[j];
            Start[j] = Start[i];
            Start[i] = temp;
        }
    }
}

int count=0;
int hall;
while(count!=n)

{
int time=-1;
hall++;
for(int i =0;i {
if(had[i]==0&&Start[i]>time)
{
had[i]=1;
time = End[i];
count++;
}
}
}
cout<<hall;
}
return 0;
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-06-04 18:24
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料