ZCMU暑期训练四-C - Tokitsukaze and Discard Items

本文介绍了一个游戏场景下的算法问题,玩家需要从页面中删除特定数量的特殊物品,并探讨了如何通过最少的操作次数完成这一任务。文章提供了一种实现思路及代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

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

Output
Print a single integer — the number of operations that Tokitsukaze would do in total.

Examples
Input
10 4 5
3 5 7 10
Output
3
Input
13 4 5
7 8 9 10
Output
1
Note
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.
题面:每页纸上有k个数字有几个要删掉删掉后后面的补上去,问最少几次操作才能完场全部删除;
思路:看起来还挺简单 但是要细心才能A

#include<iostream>
using namespace std;
const int maxn = 2e5+5;
long long a[maxn];
long long n,k,m;
int main()
{
    cin >> n >> m >> k;
    long long ans = 0;
    long long s = 0;
    long long kk = k;
    long long sum = 0;
    for(int i = 0;i < m;i++)
    {
        cin >> a[i];
    }
    for(int i = 0;i < m;i++)
    {
        if(a[i] <= k + sum) s++;
        else
        {
            if(s > 0)
            {
                sum += s;
                i--;
                ans ++,s = 0;
            }
            else if((a[i]-k - sum)/kk > 10) k = (a[i]-kk)/kk*kk,i--;//跳页
            else k+=kk,i--;
        }
    }
    if(s > 0) ans++;
    cout << ans;
    return 0;
}
<think>好的,用户想查询ZCMU OJ 1318的题目详情或解题方法。首先,我需要确认自己是否了解这个题目。由于ZCMU OJ的题目可能不在我的训练数据中,我需要根据现有的引用信息进行推断,或者给出一般性的建议。 查看用户提供的引用,发现引用1提到了1614题涉及字符串替换和大小写处理,引用2是1489题关于数气球,引用3是1900题关于并查集的应用。这些信息可能帮助用户解决类似问题,但用户明确询问的是1318题,因此需要处理这个具体的问题。 首先,我需要检查是否有关于1318题的引用,但用户给出的引用中并没有直接提到1318。因此,可能需要建议用户通过题目编号查找或根据常见题型推测。例如,ZCMU的题目可能涉及数据结构、算法或字符串处理等。考虑到引用中的其他题目涉及字符串处理和并查集,1318可能属于类似类型。 接下来,我应该建议用户检查题目链接或提供更多细节,比如题目描述或输入输出样例,以便更准确地分析。同时,可以给出常见的解题思路,比如字符串处理、动态规划或图论算法,并参考现有引用中的类似题目,如字符串处理要注意大小写(引用1),数气球可能涉及计数或哈希表(引用2),并查集用于处理连通性问题(引用3)。 如果用户无法提供更多信息,可以建议搜索ZCMU OJ的在线资源或论坛,比如官方网站、GitHub题解或相关讨论区。此外,提供通用的解题步骤,如分析输入输出、确定算法、处理边界情况等,可能对用户有帮助。 最后,生成相关问题,引导用户进一步提问或提供更多细节,以便更精准地解答。</think>根据现有资料,ZCMU OJ 1318的具体题目内容未在提供的引用中直接提及。以下是帮助您解决此类编程题目的通用方法及建议: ### 常见解题思路(适用于ZCMU OJ题型) 1. **字符串处理** 若涉及字符串操作(如引用[^1]中1614题的替换和大小写处理): ```python # 示例:字符串替换时保留大小写标记 original = "HelloWorld" positions = [0 if c.isupper() else 1 for c in original] # 记录大小写位置 modified = original.lower().replace("world", "Python") result = "".join([c.upper() if positions[i]==0 else c for i,c in enumerate(modified)]) ``` 2. **并查集应用** 若涉及连通性问题(如引用[^3]中1900题的多米诺骨牌): ```python class UnionFind: def __init__(self, n): self.parent = list(range(n+1)) def find(self, x): if self.parent[x] != x: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def union(self, x, y): self.parent[self.find(y)] = self.find(x) ``` 3. **计数与统计** 若涉及数值统计(如引用[^2]中1489题的气球计数): ```python from collections import defaultdict def count_balloons(arr): counter = defaultdict(int) for num in arr: counter[num] += 1 return max(counter.values()) if counter else 0 ``` ### 建议步骤 1. **获取题目描述** 访问ZCMU OJ官网或通过题目编号搜索获取1318题的输入输出样例及具体要求。 2. **分析问题类型** - 若涉及字符串:注意大小写处理、特殊符号过滤 - 若涉及数学:推导公式或使用动态规划 - 若涉及图论:构建邻接表或应用DFS/BFS 3. **参考相似题目** 如引用的字符串替换题需额外记录大小写位置,这种技巧可推广到其他需要保留原始格式的场景。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值