codeforce 789e Masha and geometric depression 暴力模拟

本文介绍了一种针对特定条件下的等比数列计数算法。该算法根据首项和公比的不同情况,判断数列中满足条件的项的数量,并通过使用map来存储‘bad’数组以避免数组开辟过大问题。

题意:给定一个等比数列的首项和公比b,q,(b和q都可以为0),另外给定一个数L,和m个数a[m],从首项开始计数,如果其绝对值小于等于L,则加1,然后取第二项,拿第二项当首项继续计数,直到b>L,将技术结果输出,如果有无数个,输出inf

思路:分情况,输出。

如果abs(b)>l直接判断为0.

剩下的是b<=l,如果q=1,数列全部为b,判断b是否存在“bad”数组里,不存在则有无穷个,存在之有0个

q=-1,数列为b和-b,都有无穷个,同理只要有一个不存在“bad”数组里,就有无穷个,否则有0个

q=0,b!=0 数列含有无穷个0,和一个b。

b=0,数列含有无穷个0.

剩下的暴力解,每次取一项判断绝对值是否满足条件。直到退出。

我竟然忘了有map这个东西,还在想1e9数组开不下,只能靠模拟 =_=,还有就是b要声明为long long,因为int会溢出

#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
map<long long,int> mm;
long long Abs(long long a){if(a<0)a=-a;return a;}
int main()
{
	//freopen("in.txt","r",stdin);
	int q,l,m,a;
	long long b;
	scanf("%lld%d%d%d",&b,&q,&l,&m);
	for(int i=0;i<m;i++)
	{
		scanf("%d",&a);
		mm[a]=1;
	}
	int cur=b,cnt=0;
	if(Abs(b)>l)
	{
		printf("0\n");
		return 0;
	}
	//|b|<=l
	if(q==1)
	{
		if(mm[b]==0)printf("inf\n");
		else printf("0\n");	
		return 0;
	}
	if(q==-1)
	{
		if(mm[b]&&mm[-b])printf("0\n");
		else printf("inf\n");
		return 0;
	}

	if(q==0&&b!=0)
	{
		if(mm[b]&&mm[0])printf("0\n");
		else if(mm[0]==0)printf("inf\n");
		else if(mm[b]==0)printf("1\n");
		return 0;
	}
	if(b==0)
	{
		if(mm[0]==1)printf("0\n");
		else printf("inf\n");
		return 0;
	}
	while(Abs(b)<=l)
	{
		if(mm[b]==0)
			cnt++;

		b=b*q;
	}
	//infinite q>0  b<0  && b < l
	printf("%d\n",cnt);
}

### 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 } ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值