[模拟] Codeforces - 1191C - Tokitsukaze and Discard Items
1 second
256 megabytes
standard input
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.
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.
Print a single integer — the number of operations that Tokitsukaze would do in total.
10 4 5
3 5 7 10
3
13 4 5
7 8 9 10
1
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的更多相关文章
- Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟
https://codeforces.com/contest/1191/problem/C 一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标. 至于为什么 ...
- Codeforces 1190A. Tokitsukaze and Discard Items
传送门 显然从左到右考虑每个要删除的数 维护一个 $cnt$ 表示之前已经删除了 $cnt$ 个数,那么当前所有要删除数的实际位置就要减去 $cnt$ 直接暴力枚举哪些数在最左边一个块然后一起删除 每 ...
- [Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论)
[Codeforces 1191D] Tokitsukaze, CSL and Stone Game(博弈论) 题面 有n堆石子,两个人轮流取石子,一次只能从某堆里取一颗.如果某个人取的时候已经没有石 ...
- Codeforces - 1191B - Tokitsukaze and Mahjong - 模拟
https://codeforces.com/contest/1191/problem/B 小心坎张听的情况. #include<bits/stdc++.h> using namespac ...
- 贪心+模拟 Codeforces Round #288 (Div. 2) C. Anya and Ghosts
题目传送门 /* 贪心 + 模拟:首先,如果蜡烛的燃烧时间小于最少需要点燃的蜡烛数一定是-1(蜡烛是1秒点一支), num[g[i]]记录每个鬼访问时已点燃的蜡烛数,若不够,tmp为还需要的蜡烛数, ...
- 模拟 Codeforces Round #203 (Div. 2) C. Bombs
题目地址:http://codeforces.com/problemset/problem/350/C /* 题意:机器人上下左右走路,把其他的机器人都干掉要几步,好吧我其实没读懂题目, 看着样例猜出 ...
- 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram
题目地址:http://codeforces.com/contest/435/problem/C /* 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 模拟题:蛮恶心的,不过也简单 ...
- 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie
题目传送门 /* 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 题目倒是很长:) */ #include <cstdio> #include <algorithm> ...
- queue+模拟 Codeforces Round #304 (Div. 2) C. Soldier and Cards
题目传送门 /* 题意:两堆牌,每次拿出上面的牌做比较,大的一方收走两张牌,直到一方没有牌 queue容器:模拟上述过程,当次数达到最大值时判断为-1 */ #include <cstdio&g ...
随机推荐
- 解密JDK8 枚举
写一个枚举类 1 2 3 4 5 6 public enum Season { SPRING, SUMMER, AUTUMN, WINTER } 然后我们使用javac编译上面的类,得到class文件 ...
- usb设备枚举过程
USB主机在检测到USB设备插入后,就要对设备进行枚举了.为什么要枚举呢?枚举就是从设备读取一些信息,知道设备是什么样的设备,如何进行通信,这样主机就可以根据这些信息来加载合适的驱动程序.调试USB设 ...
- 使用BIND搭建内部DNS服务
...
- 对BFC的深层理解
BFC(Block Formatting Context)块级格式化上下文 注意:BFC首先是块,其次需要具备下面的条件之一才可以(通俗来说,BFC就好比一所985或者211的高校,想要成为985或者 ...
- C++扬帆远航——6(三色球)
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:sanseqiu.cpp * 作者:常轩 * 完成日期:2016 ...
- Golang/Python/PHP带你彻底学会gRPC
目录 一.gRPC是什么? 二.Protocol Buffers是什么? 三.需求:开发健身房服务 四.最佳实践 Golang 1. 安装protoc工具 2. 安装protoc-gen-go 3. ...
- hue初识
Hue Web应用的架构 Hue 是一个Web应用,用来简化用户和Hadoop集群的交互.Hue技术架构,如下图所示,从总体上来讲,Hue应用采用的是B/S架构,该web应用的后台采用python编程 ...
- go语言指南之切片练习
题目: 实现 Pic.它应当返回一个长度为 dy 的切片,其中每个元素是一个长度为 dx,元素类型为 uint8 的切片.当你运行此程序时,它会将每个整数解释为灰度值(好吧,其实是蓝度值)并显示它所对 ...
- js面试-手写代码实现new操作符的功能
我们要搞清楚new操作符到底做了一些什么事情? 1.创建一个新的对象 2.将构造函数的作用域赋给新对象(因此this指向了这个新对象) 3.执行构造函数中的代码(为这个新对象添加属性) 4.返回新对象 ...
- 解决vue2.0下IE浏览器白屏问题
公司新开发的项目需要兼容到IE9+ 就在index.html页面加入 <meta http-equiv="X-UA-Compatible" content="IE= ...