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. Installation of the latest version of netease-cloud-music on Fedora 30 linux platform

    Installation of the latest version of netease-cloud-music on Fedora 30 linux platform Abtract As we  ...

  2. RabbitMQ 全套

    本博客代码运行环境 ErLang: ErLang_X64_22 version RabbitMQ: RabbitMQ_Server_3.7.15 version python : Python 3.7 ...

  3. onupdate

    数据的初始化显示刚开始写在onupdate中,文档类中的数据更新之后,希望通过调用UpdateAllViews(FALSE)来实现视图的更新,可以实现!后来觉得不妥,想把初始化显示写在ondraw中, ...

  4. Java常用类库API之数字处理工具类

    数字处理工具类BigDecimal和DecimalFormat Java提供的java.text.DecimalFormat类,帮助我们用最快的速度将数据格式化为我们想要的样子.例如,取两位小数 im ...

  5. 在 CentOS 上部署 GitLab (自托管的Git项目仓库)

    参考资料https://github.com/mattias-ohlsson/gitlab-installer/blob/master/gitlab-install-el6.sh 环境准备OS: Ce ...

  6. Python---基础---常用的内置模块(Github、P有charm、math数学模块和random随机数模块,做一些简单的练习)

    2019-05-24 ----------------------------------

  7. LeetCode--043--字符串相乘(java)

    给定两个以字符串形式表示的非负整数 num1 和 num2,返回 num1 和 num2 的乘积,它们的乘积也表示为字符串形式. 示例 1: 输入: num1 = "2", num ...

  8. 关于VS调试

    环境配置始终是我的弱项,碰到关于环境配置的问题就各种束手无策.但是这种事情,不能总凑合着,尤其你进不去环境或者没法调试的时候,代码写的多漂亮都没用.下面就来说一下最近关于调试的了解. 首先我们现在的项 ...

  9. vivo面试题

    0.自动拆箱和装箱 java有8种原始类型,分为数字型,字符型,布尔型.其中数字型又分为整数型和浮点数型.整数型按照占用字节数从小到大依次是byte(占用1个字节,值范围是[-27 ~ 27-1]). ...

  10. python全栈开发,Day41(线程概念,线程的特点,进程和线程的关系,线程和python理论知识,线程的创建)

    昨日内容回顾 队列 队列:先进先出.数据进程安全 队列实现方式:管道+锁 生产者消费者模型:解决数据供需不平衡 管道 双向通信,数据进程不安全 EOFError: 管道是由操作系统进行引用计数的 必须 ...