Tokitsukaze and Discard Items
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Recently, Tokitsukaze found an interesting game. Tokitsukaze had nn items at the beginning of this game. However, she thought there were too many items, so now she wants to discard mm (1≤m≤n1≤m≤n) special items of them.

These nn items are marked with indices from 11 to nn. In the beginning, the item with index ii is placed on the ii-th position. Items are divided into several pages orderly, such that each page contains exactly kk positions and the last positions on the last page may be left empty.

Tokitsukaze would do the following operation: focus on the first special page that contains at least one special item, and at one time, Tokitsukaze would discard all special items on this page. After an item is discarded or moved, its old position would be empty, and then the item below it, if exists, would move up to this empty position. The movement may bring many items forward and even into previous pages, so Tokitsukaze would keep waiting until all the items stop moving, and then do the operation (i.e. check the special page and discard the special items) repeatedly until there is no item need to be discarded.

Consider the first example from the statement: n=10n=10, m=4m=4, k=5k=5, p=[3,5,7,10]p=[3,5,7,10]. The are two pages. Initially, the first page is special (since it is the first page containing a special item). So Tokitsukaze discards the special items with indices 33 and 55. After, the first page remains to be special. It contains [1,2,4,6,7][1,2,4,6,7], Tokitsukaze discards the special item with index 77. After, the second page is special (since it is the first page containing a special item). It contains [9,10][9,10], Tokitsukaze discards the special item with index 1010.

Tokitsukaze wants to know the number of operations she would do in total.

Input

The first line contains three integers nn, mm and kk (1≤n≤10181≤n≤1018, 1≤m≤1051≤m≤105, 1≤m,k≤n1≤m,k≤n) — the number of items, the number of special items to be discarded and the number of positions in each page.

The second line contains mm distinct integers p1,p2,…,pmp1,p2,…,pm (1≤p1<p2<…<pm≤n1≤p1<p2<…<pm≤n) — the indices of special items which should be discarded.

Output

Print a single integer — the number of operations that Tokitsukaze would do in total.

Examples
input

Copy
10 4 5
3 5 7 10
output

Copy
3
input

Copy
13 4 5
7 8 9 10
output

Copy
1
Note

For the first example:

  • In the first operation, Tokitsukaze would focus on the first page [1,2,3,4,5][1,2,3,4,5] and discard items with indices 33 and 55;
  • In the second operation, Tokitsukaze would focus on the first page [1,2,4,6,7][1,2,4,6,7] and discard item with index 77;
  • In the third operation, Tokitsukaze would focus on the second page [9,10][9,10] and discard item with index 1010.

For the second example, Tokitsukaze would focus on the second page [6,7,8,9,10][6,7,8,9,10] and discard all special items at once.

题意:

一开始有n个数,这些数从1到n编号,每k个数为一组,现在给出m个要删去的特殊数,有一种操作,从第一个包含特殊数的组开始删,一次可以把一组里所有特殊数删掉,删掉数后会有空位,这些空位会被后面的数依次补上,并形成新的组,问最少需要操作多少次

思路:

考虑当前最多可以删到那个数,并求出那个数的坐标,就要知道最大可以到哪个坐标,现在定义一个最大容纳量,
最大容纳量=页数*页容量+删掉的数,页数=1+要再翻多少页(从第1页开始),
要再翻多少页=(当前坐标-已经删掉的个数-1)/页容量(-1是减去它本身)
一直删到不能再删(已经删的个数要小于等于m且最大坐标要小于等于最大容纳量)
每次统计操作次数

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int amn=1e5+;
ll n,m,k,sp[amn];
int main(){
ios::sync_with_stdio();
cin>>n>>m>>k;
for(int i=;i<m;i++)
cin>>sp[i];
ll tp=,ans=,jg;
while(tp<=m){
jg=((sp[tp]-tp-)/k+)*k+tp; ///最大容纳量=页数*页容量+删掉的数,页数=1+要再翻多少页(从第1页开始),要再翻多少页=(当前坐标-已经删掉的个数-1)/页容量(-1是减去它本身)
while(tp<=m&&sp[tp]<=jg)tp++; ///一直删到不能再删(已经删的个数要小于等于m且最大坐标要小于等于最大容纳量)
ans++;
}
printf("%lld\n",ans);
}
/***
一开始有n个数,这些数从1到n编号,每k个数为一组,现在给出m个要删去的特殊数,有一种操作,从第一个包含特殊数的组开始删,一次可以把一组里所有特殊数删掉,删掉数后会有空位,这些空位会被后面的数依次补上,并形成新的组,问最少需要操作多少次
考虑当前最多可以删到那个数,并求出那个数的坐标,就要知道最大可以到哪个坐标,现在定义一个最大容纳量,
最大容纳量=页数*页容量+删掉的数,页数=1+要再翻多少页(从第1页开始),
要再翻多少页=(当前坐标-已经删掉的个数-1)/页容量(-1是减去它本身)
一直删到不能再删(已经删的个数要小于等于m且最大坐标要小于等于最大容纳量)
每次统计操作次数
***/

[模拟] Codeforces - 1191C - Tokitsukaze and Discard Items的更多相关文章

  1. Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟

    https://codeforces.com/contest/1191/problem/C 一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标. 至于为什么 ...

  2. Codeforces 1190A. Tokitsukaze and Discard Items

    传送门 显然从左到右考虑每个要删除的数 维护一个 $cnt$ 表示之前已经删除了 $cnt$ 个数,那么当前所有要删除数的实际位置就要减去 $cnt$ 直接暴力枚举哪些数在最左边一个块然后一起删除 每 ...

  3. [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)

    [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...

  4. Codeforces - 1191B - Tokitsukaze and Mahjong - 模拟

    https://codeforces.com/contest/1191/problem/B 小心坎张听的情况. #include<bits/stdc++.h> using namespac ...

  5. 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts

    题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...

  6. 模拟 Codeforces Round #203 (Div. 2) C. Bombs

    题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...

  7. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...

  8. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...

  9. queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards

    题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...

随机推荐

  1. View 属性

    关于 View 设置属性的方式: JavaxmlstyledefStyleAttrdefStyleResTheme 关于 defStyleRes 的使用,和在 xml 中声明 style=" ...

  2. 广州CVTE招聘-测试开发工程师

    内推邮箱:keweisheng@cvte.com 地点:广州 公司简介 CVTE成立于2005年,总部位于广州科学城,旗下设有多家独立的子公司,在香港设有全球服务中心,在国内设有21个营销服务中心和近 ...

  3. 常见WAF绕过思路

    WAF分类 0x01 云waf 在配置云waf时(通常是CDN包含的waf),DNS需要解析到CDN的ip上去,在请求uri时,数据包就会先经过云waf进行检测,如果通过再将数据包流给主机. 0x02 ...

  4. MyBatis配置文件中config与mapper的约束

    本文链接:https://blog.csdn.net/gaoxin_gx/article/details/100183455 Config的约束: <?xml version="1.0 ...

  5. React项目实战:react-redux-router基本原理

    React相关 React 是一个采用声明式,高效而且灵活的用来构建用户界面的框架. JSX 本质上来讲,JSX 只是为React.createElement(component, props, .. ...

  6. 对JS中事件委托的理解

    什么是事件委托: 事件委托——给父元素绑定事件,用来监听子元素的冒泡事件,并找到是哪个子元素的事件.(不理解冒泡的可以去百度下) 定义:利用事件冒泡处理动态元素事件绑定的方法,专业术语叫事件委托. 使 ...

  7. 使用PHP语言制作具有加减乘除取余功能的简单计算器

    准备工作: 使用环境 :PHPStudy 开启Apache和Mysql 打开代码编辑器 <!DOCTYPE html> <html lang="en"> & ...

  8. VUE二 生命周期详解

    vue官网对vue生命周期的介绍 Vue实例有一个完整的生命周期,也就是从开始创建.初始化数据.编译模板.挂载Dom.渲染→更新→渲染.销毁等一系列过程,我们称这是Vue的生命周期.通俗说就是Vue实 ...

  9. 记录:更新VS2019后单元测试运行卡住无法运行测试的问题。

    先说一下是如何遇到这个问题的 今天更新了Visual Studio到最新的版本,然后在运行之前建立的单元测试项目的时候一直卡住,过了一会儿以后提示 未能协商协议,等待响应在 90 秒后超时.出现此问题 ...

  10. eetcode必要技巧--动态规划(一)

    首先我们要搞清楚什么是动态规划 动态规划是运筹学中用于求解决策过程中的最优化数学方法.当然,我们在这里关注的是作为一种算法设计技术,作为一种使用多阶段决策过程最优的通用方法. 当然这个很难理解,但是按 ...