社区讨论

求助,悬赏一关

P12036 [USTCPC 2025] 摩拉参与者 3已保存回复 4

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
4 条
当前快照
1 份
快照标识符
@mhjtdusc
此快照首次捕获于
2025/11/04 08:12
4 个月前
此快照最后确认于
2025/11/04 08:12
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
int t;
int math[21];
int a,x,b,p,ans,i;
int main()
{
	math[1]=1;
	math[2]=2;
	for(i=3;i<=20;++i)
	{
		math[i]=math[i-1]+math[i-2];
	}
	cin>>t;
	for(i=1;i<=t;++i)
	{
		cin>>a>>x>>b;
		if(a==1)
		{
			p=x;
		}
		else 
		{
			for(i=1;i<=20;i++)
			{
				if((math[a]*i-i+1)==x)
				{
					p=i;
					break;
				}
			}	
		}
		if(i>20)
		{
			cout<<-1<<endl;
		}
		else
		{
			if(b==1)
			{
				cout<<p<<endl;
			}
			else if(b==2)
			{
				cout<<p+1<<endl;
			}
			else
			{
				cout<<math[b]+(b-1)*(p-1) <<endl;
			}		
		}		
		
	}
	return 0;
}
//1 2 3 5 8 13
//2 3 5 8 13 21
//3 4 7 11

回复

4 条回复,欢迎继续交流。

正在加载回复...