Uva 1319 - Maximum 解题报告(数学)

96 篇文章 0 订阅

1319 - Maximum

Time limit: 3.000 seconds

Let x1x2,..., xm be real numbers satisfying the following conditions:

a)
-$ {\frac{​{1}}{​{\sqrt{a}}}}$$ \le$xi$ \le$$ \sqrt{​{5}}$ ;
b)
x1 + x2 +...+ xm = b * $ \sqrt{​{a}}$ for some integers  a and  b  (a > 0).

Determine the maximum value of xp1 + xp2 +...+ xpm for some even positive integer p.

Input 

Each input line contains four integers: mpab ( m$ \le$2000, p$ \le$12p is even). Input is correct, i.e. for each input numbers there exists x1x2,..., xm satisfying the given conditions.

Output 

For each input line print one number - the maximum value of expression, given above. The answer must be rounded to the nearest integer.

Sample Input 

1997 12 3 -318 
10 2 4 -1

Sample Output 

189548 
6

    解题报告:首先,这个式子不是太好看,我们可以将两个式子都乘以根号a,那么-1$ \le$xi*$ \sqrt{​{5}}$$ \le$a,x1*$ \sqrt{​{5}}$ + x2*$ \sqrt{​{5}}$ +...+ xm*$ \sqrt{​{5}}$ = ab。

    为了使其的p次方和最大,p又是偶数,我们可以让一部分x*$ \sqrt{​{5}}$的值为-1,一部分为a,最后一个x的范围只要在-1到a间就可以了。m最大2000,直接枚举,然后计算,最终结果除以$ \sqrt{​{5}}$^p。代码如下:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

void work(int m,int p,int a,int b)
{
    double res=0;
    for(int i=0;i<m;i++)
    {
        int last=a*b+i-(m-i-1)*a;
        if(last>=-1 && last<=a)
        {
            res+=i;
            res+=pow((double)last,p);
            res+=(double)(m-i-1)*pow((double)a,p);
            res/=pow((double)a, p/2.0);
            break;
        }
    }
    printf("%d\n", (int)(res+0.5));
}

int main()
{
    int m,p,a,b;

    while(~scanf("%d%d%d%d",&m,&p,&a,&b))
        work(m,p,a,b);
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值