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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- jQuery_页面加载问题
运行如下代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...
- 【Python】PIL模块
Python自建库,在爬虫等基础应用中更加简单好记,做整理以备自查. 目录 Image模块 open类.Save类.format类.Mode类.convert类.Size类.Info类.new类.Co ...
- x-admin
https://blog.csdn.net/u014793102/article/details/80316335
- jquery+css3实现熊猫tv导航效果
效果展示 实现原理 请看以下源代码. <div class="ph-nav" data-pdt-block="pheader-n"> <div ...
- Oracle 递归查询 (start with ...connect by ...prior)
1.connect by 是结构化查询中用到的,其基本语法是:select … from tablename start with 条件1connect by 条件2where 条件3;例:selec ...
- python3笔记十二:python数据类型-Dictionary字典
一:学习内容 字典概念 字典创建 字典访问 字典添加 字典删除 字典遍历 字典与列表比较 二:字典概念 1.使用键值对(key-value)存储,具有极快的查找速度 2.注意:字典是无序的 3.特性: ...
- 5、kubernetes资源清单之Pod应用190709
一.Pod镜像及端口 获取帮助文档 # kubectl explain pod.spec.containers spec.containers <[]object> pod.spec.co ...
- leetcode 78子集
采用回溯法:对于例子图解执行过程如下,其中向上的分支为向下递归,向下的分支为第二次递归,因此已经push了对应的下标的值,则从根到右边连起来的路径即为组合 由于整个过程类似于二叉树的中序遍历,因此代码 ...
- samba安装应用实例-2
应用实例: 先安装samba软件,yum install -y samba1.需求:共享一个目录,使用用户名和密码登录才可以访问,要求可读可写.(1)首先打开samba配置文件/etc/samba/s ...
- 阶段3 2.Spring_08.面向切面编程 AOP_5 切入点表达式的写法
写测试类来测试..也不需要整合JUnit了就是个普通的测试类. 我们要看就是有没有给我们真正的实现 记录日志 配置起作用了. 三个方法都调用一下 目前我们的配置只能对saveAccount增强 通常情 ...