题目描述
众人开会,给出每个人的时间表,找出所有可以用于开会的时间,要求:
Input
Output
解题思路
1.首先定义合适结构体记录时间点,再定义合适结构体记录时间段;
2.将每个人的时间表中对应的时间点全部映射到同一个时间轴上进行排序,然后对每个时间点,对每个人进行判断:在当前这个时间点,有多少人是空闲的,并加以记录;
3.所有时间点遍历完成后,再遍历一次,寻找可开会的时间段:以第一个时间点为起始时间点si,下一个时间点为终止时间点ei,这段时间作为第一个可供开会的时间段,然后进行判断,若ei点对应的空闲人数满足条件,则顺次后移;否则,判断该段时间是否超过一小时,若超过则按照指定格式输出,否则则顺次移动si和ei,寻找下一个时间段。如此重复知道所有时间点都被遍历完。
4.若均不满足,按要求输出即可。
实现代码
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
int s2n(string s)
{
int ans=0;
for(int i=0;i<s.size();++i)
ans=ans*10+s[i]-'0';
return ans;
}
struct dt
{
int y,mh,d,hr,mu,s;
dt(int sy=0,int smh=0,int sd=0,int sh=0,int smu=0,int ss=0)
{
y=sy;
mh=smh;
d=sd;
hr=sh;
mu=smu;
s=ss;
}
dt(const dt &p)
{
y=p.y;
mh=p.mh;
d=p.d;
hr=p.hr;
mu=p.mu;
s=p.s;
}
void clear()
{
y=0;
mh=0;
d=0;
hr=0;
mu=0;
s=0;
}
bool operator< (const dt &p) const
{
if(y!=p.y)
return y<p.y;
if(mh!=p.mh)
return mh<p.mh;
if(d!=p.d)
return d<p.d;
if(hr!=p.hr)
return hr<p.hr;
if(mu!=p.mu)
return mu<p