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. Asp.Net 保存Session的三种方式

    一.默认方式,保存在IIS进程中保存在IIS进程中是指把Session数据保存在IIS的运行的进程中,也就是inetinfo.exe这个进程中,这也是默认的Session的存方式,也是最常用的. 这种 ...

  2. springboot集成hibernate

    package com.jxd.Boot.hibernate.dao.impl; import java.util.List; import javax.persistence.EntityManag ...

  3. generator (2)

    generator 的使用 第一次调用next  时  传参没有任何意义  打印不出来任何结果 function * read(){ let a = yield 1; console.log(a); ...

  4. hashlib模块subprocess模块

    '''通过一种算法,将字符串得出一种编码内容相同则hash运算结果相同,内容稍微改变则hash值改变不可逆推相同算法,无论校验多长的数据,得到的hash值长度固定'''# import hashlib ...

  5. PHP Timer 页面运行时间监测类

    转至:http://blog.csdn.net/fdipzone/article/details/20160567 php Timer 页面运行时间监测类,可按不同key监测不同的运行时间 Timer ...

  6. onLayout初始化裁剪信息

    在EasyConstraintLayout中初始化LayoutParamsData的paths @Override protected void onLayout(boolean changed, i ...

  7. php mysql-pdo,fpm,csrf-forward-money,php7.1 in centos7

    centos7--php7.1http://zixuephp.net/article-207.htmlhttps://www.cnblogs.com/liansng/p/7680930.html ph ...

  8. Share架构的一些心得

    个人这些年,从web->system service->app 项目实战,陆陆续续经历的项目很多,自己也数不清.自己也一直对于架构没有明确去给出一个自己的定义描述. 刚好最近一直在flut ...

  9. 网络编程之TCP协议与UDP协议

    了解网络就要了解一些基本的协议今天主要跟大家分享一些关于TCP 协议UDP协议的相关知识 首先介绍一下TCP协议 TCP(Transmission Cintrol Protocol)可靠的.面向连接的 ...

  10. linux文件夹 权限为所有用户可 读写

    使用命令: sudo chmod dirname -R