大意: 一扇自动门, 若$t$时刻有人来, 并且门是关的, 自动门会打开$d$时间, [t,t+d]时刻来的人都可以进入, 现在有n个雇员, 分别在$a, 2a, ..., na$时刻来, $m$个客户, 分别在$t_1, t_2,..., t_m$时刻来, 求自动门打开的次数.

数据范围1 ≤ n, a ≤ 109, 1 ≤ m ≤ 105, 1 ≤ d ≤ 1018, 1 ≤ ti ≤ 1018

根据题目的范围, 显然要考虑枚举$m$个客户, 当一个客户$i$来的时候, 先处理$t_i$之前未处理的雇员即可.

为了防止最后还有未处理的雇员, 可以添加一个客户, 让他时间等于n*a, 显然不影响答案.

#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
using namespace std;
typedef long long ll; const int N = 1e6+10;
ll n, m, a, d, t[N];
int main() {
scanf("%lld%lld%lld%lld", &n, &m, &a, &d);
REP(i,1,m) scanf("%lld", t+i);
ll now = 0, ans = 0, cur = 1;
t[++m] = n*a;
PER(i,2,m) if (t[i]<t[i-1]) swap(t[i],t[i-1]);
REP(i,1,m) {
if (cur<=n&&cur*a<t[i]) {
now = cur*a;
ll r = d/a+1, tot = (t[i]-now)/a+1;
ll q = tot/r;
if (q) {
ans += q;
now += (q-1)*r*a+d;
tot -= q*r;
cur = now/a+1;
}
if (tot) {
++ans;
now = cur*a+d;
cur = now/a+1;
}
}
if (now>=t[i]) continue;
now = t[i]+d;
cur = now/a+1;
++ans;
}
printf("%lld\n", ans);
}

Automatic Door CodeForces - 883A的更多相关文章

  1. Codeforces Round #434 (Div. 2, based on Technocup 2018 Elimination Round 1)&&Codeforces 861C Did you mean...【字符串枚举,暴力】

    C. Did you mean... time limit per test:1 second memory limit per test:256 megabytes input:standard i ...

  2. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  3. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  4. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  5. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  6. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  7. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  8. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  9. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

随机推荐

  1. Topcoder SRM 674 Div.2题解

    T1 解题思路 这题应该不是很难,主要是题意理解问题. 注意给出的两个数组里映射关系已经对应好了,只要判断是否为双射即可 参考程序 #include <bits/stdc++.h> usi ...

  2. vue-cli中route和router的区别

    在使用vue-router的时候经常分不清router和route的区别: 在函数式编程中: this.$router.push('/login') 或者Router.push() 在动态获取路由参数 ...

  3. git远程相关

    git remote add origin git仓库地址 // 添加了远程仓库 git remote remove origin // 移除远程仓库 git push -u origin maste ...

  4. 【Python】学习笔记一:Hello world

    前言 在我看来,无论我们学习什么语言第一个学习的估计都是Hello world,那么接下来就从Hello world说起! 编写代码 我在本机上已经安装了pycharm,所以我所编辑的代码都是在pyc ...

  5. 在Idea下配置Maven

    Idea 自带了apache maven,默认使用的是内置maven,所以我们可以配置全局setting,来调整一下配置,比如远程仓库地址,本地编译环境变量等. 使用IDEA自带的maven时,若不配 ...

  6. TCP定时器 之 延迟确认定时器

    TCP在收到数据段但是无需马上确认时设定,如果在超时时间之内有数据要发送到对端,则确认会随着数据一起发送,即捎带ACK,如果达到超时时间则执行定时器回调立即发送ack: 启动定时器: 延迟确认定时器调 ...

  7. HTML控件 隐藏

    div的visibility可以控制div的显示和隐藏,但是隐藏后页面显示空白: style="visibility: none;" document.getElementById ...

  8. note:开源许可证之间的区别

    最近接触开源项目比较多,关注一下许可证的问题. 饱受诟病的病毒式copyleft就是GPL了.. ref:http://code.csdn.net/news/2819582 ref:http://ww ...

  9. Mysql 基础操作命令

    1,查看mysql的建表语句 show create table tableName; #tableName 库中已存在的表名

  10. leetcode-easy-dynamic-70 Climbing Stairs

    mycode  65% class Solution(object): def climbStairs(self, n): """ :type n: int :rtype ...