貌似题目有问题,第二站不是有人上下车吗?
查看原帖
貌似题目有问题,第二站不是有人上下车吗?
610643
maktoub楼主2022/12/9 20:12

题目是不是有问题,貌似测试样例的第三个,第二站上车人数是0,因为从0开始的话,超时,如果从0开始找的话就ac

#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,n,m,x;
	cin>>a>>n>>m>>x;
	if(x==1||x==2){
		cout<<a;
		return 0;
	}
	else if(x==3){
		cout<<2*a;
		return 0;
	}
	int b; 
	for(b=0;;b++){//第二站 ,卡死在这里, 
		int sum=2*a;
		int t1=a,t2=b;
		for(int i=4;i<n;i++){
			sum+=t2;
			int temp=t2;//保存上一次的 
			t2=t1+t2;
			t1=temp;//上上次的变为上一次的 
		}
		if(sum==m){
			break;
		} 
	}

	int t1=a;
	int t2=b;
	int res=2*a;
	for(int i=4;;i++){
		res+=t2;
		if(i==x){
			cout<<res;
			return 0;
		}
		int temp=t2;//保存上一次的 
		t2=t1+t2;
		t1=temp;//上上次的变为上一次的 
	}
} 
2022/12/9 20:12
加载中...