上图所示的是题目给的样例,四天每天赚的钱
一开始想着这题遍历肯定超时,应该可以用二分,随后反应过来,直接解个方程不就好啦,F(x)≥m(F(x)为工作x天赚的钱)
F(x)=(d/2)x2+(n-d/2)x
虽然很简单,,,,,,,,不过忘记考虑d=0的情况,WA得我。。。。。。。。。。。
#include<cmath>
#include<iostream>
using namespace std;
double n,m,d,x;
void solve()
{
double a=d*0.5,b=n-d*0.5,c=-m,x1,x2;
double delta=b*b-4*a*c;
delta=sqrt(delta);
if(a==0)
{
x1=m/b;
x2=x1;
}
else
{
x1=(-b-delta)/(a+a);
x2=(-b+delta)/(a+a);
}
/*if(x1<=0&&x2<=0)
{
cout<<"1"<<endl;
return;
}*///发现这段判断赘余,注释掉舍不得删,233
double ans=max(x1,x2);
cout<<(long long)ceil(ans)<<endl;
return;
}
int main()
{
cin>>n>>m>>d>>x;
getchar();
solve();
return 0;
}
If you think that my codes were useful, give me a like! (Z个B)
^ - ^