ACM一道题,这题用线段树都没办法,数据太大了LL's cafeTime Limit:5 Sec Memory Limit:128 MBSubmissions:127 Solved:47DescriptionLL opens a new cafe and he knows N customers will come tomorrow and the time of their appearance and departure

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/07 17:02:43
ACM一道题,这题用线段树都没办法,数据太大了LL''scafeTimeLimit:5SecMemoryLimit:128MBSubmissions:127Solved:47DescriptionLLo

ACM一道题,这题用线段树都没办法,数据太大了LL's cafeTime Limit:5 Sec Memory Limit:128 MBSubmissions:127 Solved:47DescriptionLL opens a new cafe and he knows N customers will come tomorrow and the time of their appearance and departure
ACM一道题,
这题用线段树都没办法,数据太大了
LL's cafe
Time Limit:5 Sec Memory Limit:128 MBSubmissions:127 Solved:47
Description
LL opens a new cafe and he knows N customers will come tomorrow and the time of their appearance and departure.LL wants to know how many seats he should buy in advance to hold all customers tomorrow at least.Note :1.One seat can only hold one customer at any time.2.Suppose A leave at time t,and B come at time t,then they can’t sit at the same seat.
Input
There are multiple cases ended with EOF.Every case is terminated with a blank line .The first number of each case is one number——N (1

ACM一道题,这题用线段树都没办法,数据太大了LL's cafeTime Limit:5 Sec Memory Limit:128 MBSubmissions:127 Solved:47DescriptionLL opens a new cafe and he knows N customers will come tomorrow and the time of their appearance and departure

#include<iostream>
#include<algorithm>
using namespace std;
struct TV{
\x05int begin;
\x05int end;
}Tv[100005];
bool cmp(TV a,TV b)
{
\x05return a.end < b.end;

int main()
{
\x05int n,i;
\x05while(scanf("%d",&n)!=EOF)
\x05{
\x05\x05int cnt=0;
\x05\x05for(i=0;i<n;i++)
\x05\x05\x05scanf("%d%d",&Tv[i].begin,&Tv[i].end);
\x05\x05sort(Tv,Tv+n,cmp);
\x05
\x05\x05int End=Tv[0].end;
\x05\x05for(i=1;i<n;i++){
\x05\x05\x05if(Tv[i].begin>End)
\x05\x05\x05{
\x05\x05\x05\x05cnt++;
\x05\x05\x05\x05End=Tv[i].end;
\x05\x05\x05}
\x05\x05}
\x05\x05printf("%d\n",n-cnt);
\x05}
\x05return 0;
}
参考这个代码哈.

思路:
首先把开始时间都从早到晚排序,然后从第一个开始往下数,(同时设一个comp标志,用来进行比较).情况有主要两种.


        1. 只要Ti[i].e即结束时间比上comp.e还早,那么,我们就选中这个而抛弃原来的comp.e,并把这个Ti[i].s还有Ti[i].e标志为comp. 
        2. 只要Ti[i].s大于comp.s,我们就要在num上加一,即在加一个可以坐的位置.同时将次节目的Ti[i].s以及Ti[i].e标志为comp.s和comp.e  .

ACM一道题,这题用线段树都没办法,数据太大了LL's cafeTime Limit:5 Sec Memory Limit:128 MBSubmissions:127 Solved:47DescriptionLL opens a new cafe and he knows N customers will come tomorrow and the time of their appearance and departure 一道acm的排序题Snow_storm有n(0 杭电acm的一道题,不知道自己错在哪,求助Input输入数据包含多个测试实例,每个测试实例占一行,每行的开始是一个整数n(3 一道数据统计填空题. 一道数学线段题求解? c++ ACM的一道题!Description 给你n个整数,求他们中所有奇数的乘积.Input 输入数据包含多个测试实例,每个测试实例占一行,每行的第一个数为n,表示本组数据一共有n个,接着是n个整数,你可以假设每 c语言acm题 acm刷题是什么意思 一道数学题,已知线段AB=acm,A1平分AB,A2平分AA1,A3平分AA2,.,An平分AAn-1,则AAn=()cm. 阶乘所得结果的位数怎么算?这是一道acm编程题. acm的一道c语言问题 一道初中几何题,请详细说明解法,(图)(图) 已知:如图,点C在线段AB上,以AC和BC为边在AB的同侧作正三角形ΔACM和ΔBCN,连接AN、BM,分别交CM、CN于点P、Q.求证:PQ∥AB. 初二的一道证明题,才华横溢的各位拜托了~(有图)如图1所示,点C为线段AB上一点,△ACM和△CBN是等边三角形,直线AN、MC交于点E,直线BM、CN交于点F. (1)求证:AN=BM; (2)求证:△CEF是等边 一道题(就是数平行线段) 求助一道ACM题一道很简单的ACM题目,题在这里我写的代码如下:#include using namespace std;int main(){int n,m[30];cin>>n;for(int i=0;i=0;j--){cout ACM的一道题,但是数字大了,过不了!.2的64次方应该用什么类型保存! ACM题中一句话看不懂Process to end of file 那什么叫把数据输出到文件的末尾呢? 一道ACM 数字统计 描述:给出一个整数n(1