http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_5_A The Maximum Number of Customers

Idea: find the most overlapped segment.  Similiar to the line painting

Mark the left and right element, x: L, O: R

#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
//https://www.hustyx.com/cpp/5/ -- reference
#define N 100005
int a[N];
int main(){
//input
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
memset(a,,N);
int n,t,l,r;
scanf("%d %d",&n,&t);
for(int i = ; i<n; i++){
scanf("%d %d",&l,&r);
a[l]++;
a[r]--;
}
//preprocess in the array
int max = ;
int count = ;
for(int i = ; i<N; i++){
count += a[i];
if(max<count) max = count;
}
printf("%d\n",max);
//printf("wei");
return ;
}

C++ learning from this code

* redefine the stream from input file

freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);

* memset in cstring

最新文章

  1. npapi插件开发流程与实例
  2. Oracle Database 11g Release 2(11.2.0.3.0) RAC On Redhat Linux 5.8 Using Vmware Workstation 9.0
  3. Unsupported major.minor version 52.0
  4. oracle计算两行差值
  5. svg是什么
  6. Web前端开发规范文档
  7. 部署报表和 ReportViewer 控件 rdlc
  8. leetcode single number系列
  9. ASP.ENT Core Linux 下 为 donet创建守护进程(转载)
  10. 总结iframe高度自适应,自适应子页面高度
  11. windows查询端口
  12. request.getParameter() 和request.getAttribute() 区别
  13. 获取某个元素第一次出现在数组(json数组)的索引
  14. python基础系列教程,数学基础系列教程,数据分析系列教程,神经网络系列教程,深度学习系列视频教程分享交流
  15. html图片上传阅览并且点击放大
  16. Linux 定时任务 crontab 和 Systemd Timer
  17. c++11并发之std::thread
  18. puppet应用案例
  19. [转载]WeeksInAYear、WeeksInYear、DaysInAYear、DaysInAMonth、DaysInYear、DaysInMonth - 获取指定年月的周、日数
  20. i春秋CTF web题(1)

热门文章

  1. poj3349找相同的雪花(哈希)
  2. MVC中Cookies的简单读写操作
  3. SyntaxError: (unicode error) &#39;unicodeescape&#39; codec can&#39;t decode bytes in position 2-3: truncated \UXXXXXXXX escape错误原因及解决方法
  4. kubernetes命令补全
  5. idea进行断点快捷键
  6. Linux配置SSH免密码登录
  7. tcp 粘包 和 TCP_NODELAY 学习
  8. Django-5.2 模型层 多表操作
  9. IntelliJ IDEA里找不到javax.servlet的jar包
  10. Mongodb installation &amp; userguide