qq_35148303
2017-06-03 08:26一道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条回答
为你推荐
- ACM题目(老是格式错误)(求c或c++解决)
- c
- acm
- c++
- 3个回答
- ACM问题 简单汉诺塔。。。。
- acm
- 2个回答
- acm 编译错误,求大神。。。。。c++
- acm
- c++
- string 字符串
- 1个回答
- 隐藏的密码 ACM中的竞赛题
- c
- 编程
- 语言
- 1个回答
- ACM里面的超时问题(困惑)
- acm
- 1个回答
换一换