zznuoj 2171: 春天的致富梦

http://47.93.249.116/problem.php?id=2171

 

真正的水题。

设走了x公里,那么水的价格为x元,因为要安全返回,所以要来回两趟要喝2x升水,所以剩余m-2x升可以卖,因此利润为(m-2x)*x元 ,一元二次方程组,开口向下,求最大值。

有题意可得,携带m升的最大价值为(m-2x*x一元二次方程组求最大值即可。

 

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<vector>
#include<math.h>
#include<string>
#include<time.h>
using namespace std;
#define INF 0x3f3f3f3f
#define LL long long
#define N 10000009
#define mid 10000000
int main()
{
    LL n,m;
    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        LL sum=0;
        LL d=(LL)(1.0*m/4+0.5);
        sum=n/m*(m-2*d)*d;
        m=n%m;
        if(m)
        {
            d=(int)(1.0*m/4+0.5);
            sum+=(m-2*d)*d;
        }
        printf("%lld\n",sum);
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/a719525932/p/9498318.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值