Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟
https://codeforces.com/contest/1191/problem/C
一开始想象了一下,既然每次删除都是往前面靠,那么好像就是页数*页容量+空位数=最多容纳到的坐标。
至于为什么呢?好像是每次都会删除干净的原因,从第一页开始考虑,第一页可以容纳到5,这个很显然。
删除之后有2个空位,然后可以容纳到7。再把7也删除,就可以容纳到8。
那么每次就暴力删除特殊元素就可以了,反正最多就是m个。
问题在于翻页的时候不能够简单的curpage++,这样必定翻车。我是直接二分,因为顶多就是分m次logn,非常小。看了别人的可以每次O(1)得到。
具体的做法是:比如现在取不出队首的元素a[i]了,直接翻到哪一页呢?最多容纳到的坐标要比a[i]大,用a[i]减去空位数,就可以得到它当前的坐标,记做b[i],那么所需的页数就是包含b[i]的最小的k的倍数,自然就是(b[i]+k-1)/k*k。
不过复杂度都是对的,有个数组越界bug但是却没事?
#include
using namespace std;
typedef long long ll;
ll n, k;
int m;
int sumdiscard = 0;
ll curpage = 1;
int ans = 0;
int _begin = 1;
ll max_delta;
ll a[100005];
ll find_delta() {
ll l = 1, r = max_delta;
while(1) {
ll m = l + r >> 1;
if(m == l) {
if(k * (curpage + l) + sumdiscard >= a[_begin]) {
//足够大
return l;
} else {
return r;
}
}
if(k * (curpage + m) + sumdiscard >= a[_begin]) {
//足够大
r = m;
} else {
//不够大
l = m + 1;
}
}
}
int main() {
scanf("%lld%d%lld", &n, &m, &k);
max_delta = (n + k - 1) / k;
for(int i = 1; i <= m; i++) {
scanf("%lld", &a[i]);
}
while(sumdiscard < m) {
if(curpage * k + sumdiscard >= a[_begin]) {
//至少有一个特殊元素要被删除
int cnt = 0;
while(curpage * k + sumdiscard >= a[_begin]) {
_begin++;
cnt++;
}
sumdiscard += cnt;
ans++;
} else {
curpage += find_delta();
//效率可能过低
}
}
printf("%d\n", ans);
}
</details>
当然既然每次都是去k的倍数干脆curpage就不用乘k了。
```cpp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[100005];
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
//freopen("Yinku.out", "w", stdout);
#endif // Yinku
ll n, k;
int m;
while(~scanf("%lld%d%lld", &n, &m, &k)) {
for(int i = 1; i <= m; i++) {
scanf("%lld", &a[i]);
}
int sumdiscard = 0, ans = 0, _begin = 1;
ll curpage = k;
while(sumdiscard < m) {
if(curpage + sumdiscard >= a[_begin]) {
//至少有一个特殊元素要被删除
int cnt = 0;
while(_begin <= m && curpage + sumdiscard >= a[_begin]) {
_begin++;
cnt++;
}
sumdiscard += cnt;
ans++;
} else {
curpage = (a[_begin] - sumdiscard + k - 1) / k * k ;
}
}
printf("%d\n", ans);
}
}
Codeforces - 1191C - Tokitsukaze and Discard Items - 模拟的更多相关文章
- [模拟] Codeforces - 1191C - Tokitsukaze and Discard Items
Tokitsukaze and Discard Items time limit per test 1 second memory limit per test 256 megabytes input ...
- 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 723B Text Document Analysis(字符串模拟,)
题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...
- Codeforces Round #304 C(Div. 2)(模拟)
题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张 ...
- Codeforces 749C:Voting(暴力模拟)
http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...
- Educational Codeforces Round 2 A. Extract Numbers 模拟题
A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...
- Codeforces 716B Complete the Word【模拟】 (Codeforces Round #372 (Div. 2))
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
随机推荐
- 使用Jmeter聚合报告生成对比图表
背景 最近在帮别的项目组执行性能测试,使用的工具是Jmeter.接口录制和参数化前一个人已经做好了,我主要的工作就是执行脚本,撰写测试报告.事情并不复杂,可做起来却极为耗时. 首先,由于有6组账号,分 ...
- 采集容器内存并写到excel
# coding=utf-8 import os import commands import re from pyExcelerator import * def execute(cmd): sta ...
- nodejs和npm之间的关系
Node.js是JavaScript的一种运行环境,是对Google V8引擎进行的封装.是一个服务器端的javascript的解释器. 包含关系,nodejs中含有npm,比如说你安装好nodejs ...
- python tkinter实时显示曲线
from tkinter import *from tkinter import ttkimport time#画窗口root = Tk()root.geometry('1000x500')root. ...
- Redis基础系列-安装启动
安装 ①将Redis 的tar 包上传到opt 目录②解压缩③安装gcc 环境我们需要将源码编译后再安装,因此需要安装c 语言的编译环境!不能直接make! 可以上网,yum install –y g ...
- MySQL WAL
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11447794.html WAL: Write-Ahead Logging 先写日志,再写磁盘.具体说, ...
- LeetCode--049--字母异位词分组(java)
给定一个字符串数组,将字母异位词组合在一起.字母异位词指字母相同,但排列不同的字符串. 示例: 输入: ["eat", "tea", "tan&quo ...
- Change the environment variable for python code running
python程序运行中改变环境变量: Trying to change the way the loader works for a running Python is very tricky; pr ...
- js 和jquery
1. js 全称 javascript 是 web客户端 运行的 解释性语言.. 2. jquery 只不过是 js 封装 简化了 ajax 和 dhtml 的 一款js 框架而已. 简单来说 Jqu ...
- (转)原理到实现 | K8S 存储之 NFS
转:https://mp.weixin.qq.com/s/Mrr1Rnl_594Gyyn9fHekjw 1NFS介绍 NFS是Network File System的简写,即网络文件系统,NFS是Fr ...