题意:在满足两个条件的xi的情况下,使得xp1 +xp2 +...+xpm最大,首先明确p是正整数,所以我们只要满足xi越大,那么等式和就越大,现在我们就是在满足条件的情况下尽量选sqrt(a),,现将等式二两边同时乘以sqrt(a),不等式同样变成了-1<=sqrt(a)*xi <= a,所以只要tmp >= a的话,我们就可以使得x1为sqrt(a),然后再判断剩下的数,当然如果小于tmp,那么我们为了再尽快凑出一个a,所以我们选择xi为最小的,最后一个的数是无法判断的,因为它一定是有倒二的数和总和所确定的
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int l,r;
double m,p,a,b,tmp,sum;
int main(){
while (scanf("%lf%lf%lf%lf",&m,&p,&a,&b) != EOF){
tmp = a * b;
r = l = 0;
sum = 0;
for (int i = 0; i < m - 1; i++){
if (tmp >= a){
tmp -= a;
r++;
}
else {
tmp += 1;
l++;
}
}
sum += l / pow(sqrt(a),p);
sum += r * pow(sqrt(a),p);
sum += pow(tmp/sqrt(a),p);
printf("%d\n",int(sum+0.5));
}
return 0;
}