[模拟] 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 ...
随机推荐
- 11. 无数人难办事? - 迪米特法则(LoD)
11.1 第一天上班 时间: 4月2日19点 地点: 小菜大鸟住所的客厅 任务: 小菜, 大鸟 "回来啦! 怎么样? 第一天上班感受多吧." 大鸟关关心的问道. ...
- JDK_Packages_java_utils
utils包需要关注的主要有 集合框架.并发包.函数式编程.观察者模式@see PropertyChangeSupport java.util(集合框架) Contains the collect ...
- 腾讯自动化测试的AI智能
引子: 本文是林奕在腾讯 DevDays 2018 分享内容的脱敏整理,介绍了 CSIG 测试开发中心(前 SNG 测试开发中心)在自动化测试领域所做的智能化尝试. 大致分成下面几部分: 使用AI面对 ...
- OpenSSL 生成自定义证书
前言 本文用来记录通过OpenSSL生成自定义证书并在浏览器设置可信任 准备 Linux CentOS7 系统 nginx 1.12.2 Windows 10 IE 11 chrome 71 Open ...
- 这有一管信息量很大的DNA
题图:华盛顿大学副教授Luis Henrique Ceze(照片中的男士)和研究科学家Lee Organick正将数字数据保存进DNA测序,以供"读取"并追溯原始文件. 来自微软和 ...
- C++走向远洋——34(友元函数,成员函数和一般函数的区别)
*/ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:youyuan.cpp * 作者:常轩 * 微信公众号:Worl ...
- Linux - 修改系统的max open files、max user processes(附ulimit的使用方法)【转载】
Linux - 修改系统的max open files.max user processes(附ulimit的使用方法)目录 1 问题说明2 修改max open files3 修改max user ...
- Python:turtle库的使用及图形绘制
目录 一.绘制一个八边形 二.绘制一个八角图形 三.简述问题 四.循环程序设计 五.绘制一个自己喜欢的图形 一.绘制一个八边形 使用turtle库,绘制一个八边形 代码: from turtle im ...
- javascript常用工具函数总结(不定期补充)未指定标题的文章
前言 以下代码来自:自己写的.工作项目框架上用到的.其他框架源码上的.网上看到的. 主要是作为工具函数,服务于框架业务,自身不依赖于其他框架类库,部分使用到es6/es7的语法使用时要注意转码 虽然尽 ...
- 在服务器上保存图片没有权限该怎么办?Permission denied:xxxxxx
用Flask框架,写了一个上传图片的接口,把这个Flask服务用nginx+uwsgi部署在了服务器上,保存图片至服务器指定目录,显示没有权限?? 一开始我以为是nginx或者uwsgi影响的(可能很 ...