求助
查看原帖
求助
744960
Lovely_Chtholly楼主2022/12/9 22:19
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,f,k;
	cin>>a>>b>>f>>k;
	int o=b,tot=0;bool p=0;
	if(k==1&&(b<f||b<a-f))
	{
		cout<<-1;
		return 0;
	}
	if(k==2&&(b<f||b<2*(a-f)))
	{
		cout<<-1;
		return 0;
	}
	if(b<2*f||b<2*(a-f))
	{
		cout<<-1;
		return 0;
	}
	for(int i=0;i<k;i++)
	{
		if(!p)
		{
			o-=f;
			if((o<2*(a-f)&&i+1!=k)||(o<a-f&&i+1==k))
			{
				o=b;
				tot++;
			}
			o-=a-f;
		}
		else
		{
			o-=a-f;
			if((o<2*f&&i+1!=k)||(o<f&&i+1==k))
			{
				o=b;
				tot++;
			}
			o-=f;
		}
		p=!p;
	}
	cout<<tot;	
}
2022/12/9 22:19
加载中...