[NOIP模拟]购买板凳
来源:互联网 发布:mt4编程书籍 编辑:程序博客网 时间:2024/04/23 23:59
样例输入1:
2
6 08:00 09:00
5 08:59 09:59
样例输出1:
11
样例输入2:
2
6 08:00 09:00
5 09:00 10:00
样例输出2:
6
数据范围:
对于95%的数据:n≤10000;
对于100%的数据:n≤100000;1≤x≤100;0≤a,c<24;0≤b,d<60。
题目分析:
考试总结:这道题本来不难,但是考试的时候,却全挂,我在记录时间的时候,我以为我的if语句能够去重,但是实际上并不完全。考后修改后,也只能对八个点(为了找到剩下两个点错的原因,也耗费了很久的时间),还不如最后一起去重,简洁无错。(其实这道题不用去重的,不过我的写法要)。
分析:你可以把每个时间点所对应的人数增减记录下来(把时间转化成分钟数存数组),最后扫一遍,取各个时间点存在的人数中的最大值。
PS:下附代码是我考试代码修改正确后的版本,与上述分析不同,我是在判断剩余板凳数,其实是我绕远了。
附代码:
#include<iostream>#include<cstdlib>#include<cstdio>#include<ctime>#include<cmath>#include<cstring>#include<string>#include<cctype>#include<iomanip>#include<algorithm>using namespace std;const int N=2e5+100;int n,ans,num,a,b,c,d,sum,x,y;int tot,w[N],bjl[N],bjr[N];int readint() { char ch;int i=0,f=1; for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar()); if(ch=='-') {ch=getchar();f=-1;} for(;ch>='0'&&ch<='9';ch=getchar()) i=(i<<3)+(i<<1)+ch-'0'; return i*f;}int main(){ //freopen("chair.in","r",stdin); //freopen("chair.out","w",stdout); n=readint(); for(int i=1;i<=n;i++) { num=readint(); a=readint();b=readint(); c=readint();d=readint(); x=a*60+b;y=c*60+d; w[++tot]=x;//将时间存入数组 w[++tot]=y; bjl[x]+=num;bjr[y]+=num;//记录这两个时间点人数的变化 if(num>ans) ans=num; } sort(w+1,w+tot+1); tot=unique(w+1,w+tot+1)-w-1;//去重 sum=ans; num = 0;//sum代表剩余的板凳数 for(int i=1;i<=tot;i++)//这里你可以直接枚举1~1440,也就无需去重了 { if(bjr[w[i]]!=0) sum+=bjr[w[i]]; if(bjl[w[i]]!=0) { if(sum>=bjl[w[i]]) sum-=bjl[w[i]]; else {ans+=bjl[w[i]]-sum;sum=0;}//不够,于是补上差的 } } printf("%d",ans); return 0;}
阅读全文
1 0
- [NOIP模拟]购买板凳
- 板凳
- Noip模拟
- 【NOIP模拟】20151004模拟
- 【NOIP模拟】 20151005模拟
- 【NOIP模拟】 20151006模拟
- 【NOIP模拟】 20151007模拟
- 【NOIP模拟】20151014模拟
- 【NOIP模拟】20151015模拟
- 【NOIP2012模拟10.6】购买
- 火车票购买系统模拟
- 【09 NOIP 模拟】light
- [NOIP模拟]Day1
- 8.9CH NOIP模拟
- 8.10FCH NOIP模拟
- 8.13NOIP模拟
- 8.14NOIP模拟
- noip模拟赛 双城记
- ES6中的解构赋值
- YOLT——利用卷积神经网络对卫星影像进行多尺度目标检测
- C语言简历
- mfc sql数据库
- 96. Unique Binary Search Trees
- [NOIP模拟]购买板凳
- 第七周项目三__负数把正数赶出队列
- 权限管理说明-以Linux为例
- c++构造函数盲目拷贝期待引用类型的实参
- SpringBoot微服务的https配置方法(即微信小程序后台服务搭建解决方案)
- 【BZOJ】4326 NOIP2015 运输计划 二分+LCA+树上差分
- 杭电OJ-1285(队伍排名)
- Tensorflow GPU安装错误解决方法
- Java登录认证-基于userId+token-框架flylib-passport