题解:CF2051B Journey

CF2051B Journey

思路

先计算 \(a,b,c\) 都一定会走的次数,也就是 \(n/(a+b+c)\),记结果 \(num\),为然后再一个一个枚举:

  • 剩下的 \(n=0\):答案为 \(num\cdot3\)
  • 剩下的 \(n\le a\):答案为 \(num\cdot3+1\)
  • 剩下的 \(a\lt n\le a+b\):答案为 \(num\cdot3+2\)
  • 剩下的 \(a+b\lt n\):答案为 \(num\cdot3+3\)

AC 代码

#include<bits/stdc++.h>
using namespace std;
long long t,n,a,b,c;
int main(){
	cin>>t;
	while(t--){
		cin>>n>>a>>b>>c;
		long long num=n/(a+b+c);
		n-=num*(a+b+c);
		if(n==0) cout<<num*3<<endl;
		else if(a>=n) cout<<num*3+1<<endl;
		else if(a+b>=n) cout<<num*3+2<<endl;
		else cout<<num*3+3<<endl;
	}
	return 0;
} 

AC 记录

posted @ 2024-12-27 11:30  SuperJimmy  阅读(12)  评论(0)    收藏  举报