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个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...
随机推荐
- 翻译一篇英文文章,主要是给自己看的——在ASP.NET Core Web Api中如何刷新token
原文地址 :https://www.blinkingcaret.com/2018/05/30/refresh-tokens-in-asp-net-core-web-api/ 先申明,本人英语太菜,每次 ...
- echarts 有关饼形图和map的使用技巧1(饼图)
http://blog.csdn.net/yhn1121/article/details/52041742 先上个链接,百度无意间搜到的,写得比我全面,可以直接飞去看它: 之前写网页用过echarts ...
- 利用jquery动态添加和删除表格的一行,并且保存单行数据
开发时遇到一个需求:要求要在页面的表格可以添加和删除一行,并能填写对应的数据后保存这一行数据. HTML代码 界面使用了freemarker框架,teams是后台传过来的list类型数据 <fo ...
- 关于Spring3与Jdk8 遇到的问题ArrayIndexOutOfBoundsException:xxxxxx
Spring 3不完全兼容JDK8. 需要升级到Spring 4才能使用Java 8 lambda表达式.
- css3 水纹效果(仿写阿里云)
效果图 什么也不说了,上代码. <!DOCTYPE html> <html> <head> <title>css3 水纹效果</title> ...
- C++入门经典-例3.10-根据输入的字符输出字符串
1:代码如下: // 3.10.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #inc ...
- C# 截取屏幕局部
//截取全屏图象 private void btnFullScreen_Click(object sender, EventArgs e) { //创建图象,保存将来截取的图象 Bitmap imag ...
- c++中字符输入函数cin.getline在输入char与string时的不同
cin.getline在输入char时: using namespace std; ; char name[ArSize]; char dessert[ArSize]; cout << & ...
- 获取当前线程状态--Thread类
String msgToPrint = Thread.currentThread().getStackTrace()[3] .getMethodName(); 就是调用时的方法名. 其中使用的Thre ...
- emqtt 系统主题
$SYS-系统主题 EMQ 消息服务器周期性发布自身运行状态.MQTT 协议统计.客户端上下线状态到 $SYS/ 开头系统主题. $SYS 主题路径以 “$SYS/brokers/{node}/” 开 ...