标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 1616 Accepted Submission(s): 580
2 2 6 08:00 09:00 5 08:59 09:59 2 6 08:00 09:00 5 09:00 10:00
11 6
//错误的思路!!!!!!(花费两个小时就没改出错误,原来思路错了)
//1-2:2 1.5-3:3 2-4:4
//用这种思路想的话,就得用9个板凳,但是实际上7个就行了,所以思路有问题@@!1!
//板凳问题是考虑区间重叠问题,而南阳的14会场安排,杭电的2037今年暑假不AC这题还不一样,
//这两道是是求不重叠区间的个数最多的问题,二这个题是求重叠区间的问题,完全不同,以后看见
//不重叠区间的话就要想想会场安排和今年暑假不AC,当看见重叠区间的问题的话,就考虑板凳问题!
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
struct node
{
int num;
int t1;
int t2;
}a[10005];
int cmp(node u,node v)
{
if(u.t2==v.t2)
return u.num>v.num;
return u.t2<v.t2;
}
int main()
{
int n,m,i,j,k,b,c,d,e,t,s,sum;
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d %d:%d %d:%d",&a[i].num,&b,&c,&d,&e);
a[i].t1=b*100+c;
a[i].t2=d*100+e;
}
sort(a,a+n,cmp);
for(i=1,t=a[0].t2,s=a[0].num;i<n;i++)
{
if(a[i].t1<t&&a[i].t2>t)
{
s+=a[i].num;
t=a[i].t2;
}
else if(a[i].t1<t&&a[i].t2==t)
{
s+=a[i].num;
}
else if(a[i].t1>=t&&a[i].num<=s)
{
t=a[i].t2;
}
else if(a[i].t1>=t&&a[i].num>s)
{
s+=(a[i].num-s);
t=a[i].t2;
}
}
printf("%d\n",s);
}
return 0;
}/*
用时:1000ms
*/
//这种方法超时!思路是为了求所需要的最多的板凳,所以我们要算出都是在什么时候需要板凳,所以
//我算了时间的最大值和最小值,然后,然后我再遍历看看输入的哪个时间段里面有这个时间,然后就
//说明这个时间需要凳子的个数需要加上这么多,还有很多时间段没有包含这个时刻我也必须遍历,所以花费了不少的时间
//并且还有输入数据需要花费时间,给时间排序需要花费时间,所以这么多操作导致了超时的现象,
//以后要学会变相的看待问题,如果求每个时刻的板凳不好一下子求出来的话,我们可以一下子求
//一个时间段的时间对应的板凳,都对应的赋值给他们,再输入第二个时间段各自对应的凳子,再对应的加起来
//然后求最大值,到求最大值的时候我们就又会遇到问题,那就是这个时间数组从哪个值开始,到哪个
//值结束,我们总不能重用循环来遍历找最大值吧,所以我们又需要巧妙的用条件语句穿擦到其中,将
//最大值算出来!每次就多算一条语句,又省去一个循环找最大值的时间,所以就不超时了!
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
struct node
{
int num;
int t1;
int t2;
}a[10005];
int s[2500];
int cmp(node u,node v)
{
if(u.t2==v.t2)
return u.t1<v.t1;
return u.t2<v.t2;
}
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n,m,i,j,k,b,c,d,e,t,mx;
scanf("%d",&n);
while(n--)
{
memset(s,0,sizeof(s));
scanf("%d",&m);
for(i=0;i<m;i++)
{
scanf("%d %d:%d %d:%d",&a[i].num,&b,&c,&d,&e);
a[i].t1=b*60+c;
a[i].t2=d*60+e;
}
sort(a,a+m,cmp);
for(i=a[0].t1,t=0,mx=0;i<=a[m-1].t2;i++)
{
for(j=0;j<m;j++)
{
if(i>=a[j].t1&&i<a[j].t2)
s[t]+=a[j].num;
else if(i<a[j].t1)
break;
}
mx=max(mx,s[t]);
t++;
}
printf("%d\n",mx);
}
return 0;
}//用时:967MS
//这道题的这种方法比较奇葩,他需要统计每个时刻需要多少个板凳,求其对应的板凳的最大值!
//在开始到结束这个时间段内,都需要板凳,所以那些时刻对应的数组都需要加上板凳的数目
//第二次输入的时候,也要进行计算开始的时间和结束的时间,然后再开始和结束的时间内都需要在对应的数组上加上
//所需板凳的数目;以此类推,直到m个为止,这既能算出每个时刻所需要的凳子,又能算出哪个时刻所需要的凳子最多!
//并能算出凳子最多是多少!这种方法真是太好了!
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
int n,m,i,j,k,t_begin,t_end,a,b,c,d,e,t[2000],max;
scanf("%d",&n);
while(n--)
{
memset(t,0,sizeof(t));
scanf("%d",&m);
for(i=0,max=0;i<m;i++)//通过直接嵌套的方法,带输入数值,带计算答案,又减少了m次循环!
{
scanf("%d %d:%d %d:%d",&a,&b,&c,&d,&e);
t_begin=b*60+c;
t_end=d*60+e;
for(j=t_begin;j<t_end;j++)//这个开始的时间与结束的时间的间隔比较短,循环的次数也随之减少
{
t[j]+=a;
max=(t[j]>max)?t[j]:max;
}
}
printf("%d\n",max);
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 4883 TIANKENG’s restaurant
标签:
原文地址:http://blog.csdn.net/dxx_111/article/details/47208237