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 - 模拟的更多相关文章

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

    Tokitsukaze and Discard Items time limit per test 1 second memory limit per test 256 megabytes input ...

  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 723B Text Document Analysis(字符串模拟,)

    题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...

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

    题目链接: http://codeforces.com/problemset/problem/546/C 题意: 总共有n张牌,1手中有k1张分别为:x1, x2, x3, ..xk1,2手中有k2张 ...

  7. Codeforces 749C:Voting(暴力模拟)

    http://codeforces.com/problemset/problem/749/C 题意:有n个人投票,分为 D 和 R 两派,从1~n的顺序投票,轮到某人投票的时候,他可以将对方的一个人K ...

  8. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  9. 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 ...

随机推荐

  1. uwsgi配置cheaper模式进行自动弹性

    [uwsgi] socket = 0.0.0.0:8080 protocol = http master = true hara-kiri = 60 chdir = /home/test/projec ...

  2. java判断回文数

  3. AOP技术介绍--(AOP技术基础)

    2.1 AOP技术起源        AOP技术的诞生并不算晚,早在1990年开始,来自Xerox Palo Alto Research Lab(即PARC)的研究人员就对面向对象思想的局限性进行了分 ...

  4. 插头$DP$学习小结

    插头\(DP\)学习小结 这种辣鸡毒瘤东西也能叫算法... 很优秀的一个算法. 最基本的适用范围主要是数据范围极小的网格图路径计数问题. 如果是像\(Noi2018\)那种的话建议考生在其他两道题难度 ...

  5. 关于python3 使用pycharm+unittest+html+HTMLTestRunner 测试用例运行正常,但却不能生成测试报告的解决方法

    关于python3 使用pycharm+unittest+html+HTMLTestRunner 测试用例运行正常,但却不能生成测试报告的解决方法 这个问题我也遇到过,以下是解决办法   该方法适用于 ...

  6. Flask路由之重定向

    Flask框架提供了请求重定向功能,只需要使用 redirect_to即可, 示例代码如下: from flask import Flask, render_template, request, re ...

  7. OC中保存自定义类型对象的持久化方法

    OC中如果要将自定义类型的对象保存到文件中,必须进行以下三个条件: 想要把存放自定义类型的数组进行 持久化(就是将内存中的临时数据以文件<数据库等>的形式写到磁盘上)必须满足: 1. 自定 ...

  8. myeclipse web project 名字可以包含中文吗?

    1.理论上是可以有中文名的,但是由于中文因为编码的原因导致不可预料的后果,所以一般不建议使用中文名称 2.   Myeclipse中修改Web项目名字的方法 方法一:新建项目法(有效的备份原来的项目) ...

  9. Python3解leetcode Number of Boomerangs

    问题描述: Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple ...

  10. 【CF1257E】The Contest【线段树】

    题意:给定三个序列abc,问最少操作几次使得满足a<b<c 题解:将三个序列合并起来,设cnt[i][1/2/3]表示前i个数有几个是来自序列1/2/3的. 枚举第一个序列要到i,此时对于 ...