codeforce1190A Tokitsukaze and Discard Items 模拟

本文解析了CodeForces平台上的1190A题目,该题目涉及特殊的项目丢弃规则,通过设计算法确定丢弃所有特殊项目所需的最少操作次数。

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

问题链接(https://codeforces.com/problemset/problem/1190/A)

问题描述

给出n个项目,编号为1到n,每一页有k个项目,n个项目中有m个特殊项目是要丢弃的,丢弃的方式为在最前面有特殊项目的那一页开始操作,每操作一次,所面对的那一页里的所有特殊项都会被丢弃,然后之后的项会往前移动填充这一页,如果这一页没有特殊项就要翻页去对有特殊项的页进行操作,如此操作最终把所有特殊项丢弃掉,求操作的次数。

问题分析

每操作一次就会少几个特殊项,对于原来的页来说,能操作的项目的下标也就相应增加了几个。那么按这个思路设计一个当前的上限变量maxn,对p[i]<=maxn的p[i]剔除,并记录个数e,直到不满足条件,然后对maxn扩展e,如果能有新的特殊项进入maxn的操作范围就继续剔除,如果还是不能继续操作,就翻页,也就是对maxn增加正整数倍的k,直到取完。
注意:翻页操作不要一页页翻,会超时的,可以找到当前要剔除的最小的p[i],求解相应要翻的页数,在数值间隔较大的情况小能省很多时间。

代码如下

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;

ll p[N];

int main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	int i,m,count;
	ll n,k,maxn,empty;
	cin>>n>>m>>k;
	for(i=0;i<m;i++) cin>>p[i];
	
	count=empty=i=0;
	maxn=k;//maxn=x*k+empty;
	while(i<m){
		if(p[i]<=maxn){
			while(p[i]<=maxn&&i<m){
			empty++;
			i++;
			}
			count++;
			maxn+=empty;
			empty=0;
		}
		else{
			ll temp=p[i]-maxn;//temp=x*k+c
			if(temp%k) maxn+=(temp/k+1)*k;
			else maxn+=temp; 
		}
	}
	cout<<count<<endl;
	return 0;
}
### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值