天梯赛练习题L2-042 老板的作息表(模拟)
https://pintia.cn/problem-sets/994805046380707840/exam/problems/1518582383141380096
题目大意:
给定n个工作的时间段,每个时间段都在 00:00:00 到 23:59:59 这个范围内,说明不会跨天数,也不会发生重叠(题目明确指出)。
问我们未提及的时间段是哪些?
输入样例:
8
13:00:00 - 18:00:00
00:00:00 - 01:00:05
08:00:00 - 09:00:00
07:10:59 - 08:00:00
01:00:05 - 04:30:00
06:30:00 - 07:10:58
05:30:00 - 06:30:00
18:00:00 - 19:00:00
输出样例:
04:30:00 - 05:30:00
07:10:58 - 07:10:59
09:00:00 - 13:00:00
19:00:00 - 23:59:59
一个模拟题,我用前缀和写的,但是里面有很多细节需要考虑清楚,才更容易实现。
【温馨提示】解绑处代码需注释掉,不然即将收获半天段错误大礼包
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18,MINN=-1e18;
const LL N=87000,M=4010;
const LL mod=998244353;
const double PI=3.1415926535;
#define endl '\n'
int flag[N]={0},sum[N];
int main()
{
//cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
//cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
int a,b,c,d,e,f;
scanf("%d:%d:%d - %d:%d:%d",&a,&b,&c,&d,&e,&f);
int x=c+b*60+a*60*60;
int y=f+e*60+d*60*60;
flag[x]+=1;
flag[y]-=1;
}
int idx=24*60*60-1;
vector<int> v;
sum[-1]=0;
for(int i=0;i<=idx;i++)
{
sum[i]=sum[i-1]+flag[i];
}
sum[-1]=-1;
sum[idx]=1;
for(int i=0;i<=idx;i++)
{
if(sum[i]==0&&sum[i-1]!=0)
{
//v.push_back(i);
int a=i/3600,b=(i-a*3600)/60,c=i%60;
printf("%02d:%02d:%02d -",a,b,c);
}
if(sum[i]==0&&sum[i+1]!=0)
{
//v.push_back(i+1);
int d=(i+1)/3600,e=((i+1)-d*3600)/60,f=(i+1)%60;
printf(" %02d:%02d:%02d\n",d,e,f);
}
}
/*cout<<v.size()<<" ";
for(int i=0;i<v.size();i++)
{
cout<<v[i]<<" ";
LL a=v[i]/3600;
LL b=(v[i]-a*3600)/60;
LL c=v[i]%60;
cout<<a<<" "<<b<<" "<<c<<endl;
}
cout<<endl;*/
/*for(int i=0;i<v.size();i+=2)
{
int a=v[i]/3600;
int b=(v[i]-a*3600)/60;
int c=v[i]%60;
int d=v[i+1]/3600;
int e=(v[i+1]-d*3600)/60;
int f=v[i+1]%60;
printf("%02d:%02d:%02d - %02d:%02d:%02d\n",a,b,c,d,e,f);
}*/
}
return 0;
}