Automatic Door CodeForces - 883A
大意: 一扇自动门, 若$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的更多相关文章
- 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 ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
- CodeForces - 261B Maxim and Restaurant
http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...
- CodeForces - 696B Puzzles
http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- Vue页面刷新方法(子组件改变数据后兄弟组件刷新,不闪烁)
todo https://blog.csdn.net/qq_40571631/article/details/91533248
- maven jdbc 驱动安装
https://mvnrepository.com/ 搜索 : com.microsoft.sqlserver 点击进入: https://mvnrepository.com/artifact/co ...
- Error:Connection activation failed: No suitable device found for this connection
原文链接: https://blog.csdn.net/baiboya/article/details/80452822 ens33这个网卡一直无法激活,在网上找了半天,找到这个博主的文章,才解决,虽 ...
- 20175215 2018-2019-2 第八周java课程学习总结
第十五章 泛型与几何框架 15.1 泛型 泛型(Generics)是在JDK1.5中推出的,其主要目的是可以建立具有类型安全的集合框架,如链表.散列映射等数据结构. 15.1.1 泛型类声明 可以使用 ...
- LeetCode 39. 组合总和(Combination Sum)
题目描述 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的数字可以无限 ...
- LeetCode 34. 搜索范围(search for a range)
题目描述 给定一个按照升序排列的整数数组 nums,和一个目标值 target.找出给定目标值在数组中的开始位置和结束位置. 你的算法时间复杂度必须是 O(log n) 级别. 如果数组中不存在目标值 ...
- HANA LOG日志过大处理办法
http://www.fenxiangzhe.net/archives/50 在SAP HANA 运维过程我们经常遇到因前期HANA LOG模式未设置成OVERWIRTE或者日志备份时间设置过长导致日 ...
- 浏览器端-W3School-JavaScript-HTML DOM:HTML DOM Element 对象
ylbtech-浏览器端-W3School-JavaScript-HTML DOM:HTML DOM Element 对象 1.返回顶部 1. HTML DOM Element 对象 HTML DOM ...
- PyQt4 Python GUI窗体应用程序
目录 目录 前言 软件环境 PyQT简介 Setup PyCharm Setup SIP Setup PyQt4 测试PyQt是否安装成功 常见错误 最后 前言 还是一句老话,公司要什么我就做什么.这 ...
- Selenium 2自动化测试实战11(键盘事件)
一.键盘事件 1.Keys()类提供了键盘上几乎所有按键的方法,如下实例: #coding:utf-8 from selenium.webdriver.common.keys import Keys ...