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

a)
-xi ;
b)
x1 + x2 +...+ xm = b *  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 ( m2000, p12, p 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.

#include <stdio.h>
#include <math.h> double m, p, a, b, numa, anum, sb, sum;
int main() {
while (~scanf("%lf%lf%lf%lf", &m, &p, &a, &b)) {
sum = 0;
sb = a * b;
numa = anum = 0;
for (int i = 0; i < m - 1; i ++) {//注意只进行m - 1次操作,最后一部分要单独考虑
if (sb < a) {
anum ++;
sb ++;
}
else {
sb -= a;
numa ++;
}
}
sum += anum / pow(sqrt(a), p);
sum += numa * pow(sqrt(a), p);
sum += pow((sb / sqrt(a)), p);//剩下的部分
printf("%d\n", int(sum + 0.5));
}
return 0;
}

Sample Input

1997 12 3 -318
10 2 4 -1

Sample Output

189548
6

题意:给定m,p,a,b.根据题目中的两个条件.求出 xp1 + xp2 +...+ xpm 最大值..

思路:贪心.由于题目明确了p是负数,所以x^p,x绝对值越大的时候值越大。。然后我们根据条件。发现x尽可能取sqrt(a)是最好的。但是不一定能全部取得sqrt(a)。那么多出来的还要拿一部分去抵消。这时候我们就用-1/sqrt(a)去抵消是最好的。这样就能满足最大了。不过要注意。抵消到最后剩下那部分也要考虑进去。

代码:

UVAlive 2911 Maximum(贪心)的更多相关文章

  1. uvalive 2911 Maximum(贪心)

    题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...

  2. UVALive 4867 Maximum Square 贪心

    E - Maximum Square Time Limit:4500MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit ...

  3. Maximum 贪心

    Maximum Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Des ...

  4. UVALive - 4225(贪心)

    题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...

  5. UVALive 4850 Installations 贪心

    题目链接  题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...

  6. UVALive 4863 Balloons 贪心/费用流

    There will be several test cases in the input. Each test case will begin with a line with three inte ...

  7. UVALive - 6268 Cycling 贪心

    UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:

  8. UVALive 4731 dp+贪心

    这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...

  9. UVALive 3835:Highway(贪心 Grade D)

    VJ题目链接 题意:平面上有n个点,在x轴上放一些点,使得平面上所有点都能找到某个x轴上的点,使得他们的距离小于d.求最少放几个点. 思路:以点为中心作半径为d的圆,交x轴为一个线段.问题转换成用最少 ...

随机推荐

  1. listview优化

    http://www.2cto.com/kf/201108/99928.html 项目用到ListView,由于要用到ImageView,图片源不是在资源里面的,没法使用资源ID,因此无法直接使用Si ...

  2. java转换字符串的编码(转)

    package com.Alex.base; import java.io.UnsupportedEncodingException; /** * 转换字符串的编码 */ public class C ...

  3. MATLAB介绍

    MATLAB MATLAB[1]  是美国MathWorks公司出品的商业数学软件,用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink ...

  4. Java调用Lua脚本(LuaJava使用、安装及Linux安装编译)

    依赖包(附件有下载): 包名 类型 操作系统 luajava-1.1.jar jar ALL libluajava-1.1.so .so linux luajava-1.1.dll .dll wind ...

  5. paip.QQ音乐导出歌单总结

    paip.QQ音乐导出歌单总结 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...

  6. Network()

    Network Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 60000/30000K (Java/Other) Total Submi ...

  7. 20151225--easyUI

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  8. 对于windows窗口的标题菜单栏的操作——删除/禁用 最小最大话和关闭

    HWND hand = FindWindow(NULL, "计算器"); int nStyle = GetWindowLong(hand, GWL_STYLE);nStyle &a ...

  9. zoj 3471Most Powerful

    题意:给n个atom(原子),每两个原子相碰会产生能量,不过每次碰撞会消失一个原子,而且不同原子碰撞,消失的原子不同,产生的能量也会不同,给出不同原子相碰撞产生的能量,求出能产生的最多能量. 状态DP ...

  10. [一个经典的多线程同步问题]解决方案三:互斥量Mutex

    本篇通过互斥量来解决线程的同步,学习其中的一些知识. 互斥量也是一个内核对象,它用来确保一个线程独占一个资源的访问.互斥量与关键段的行为非常相似,并且互斥量可以用于不同进程中的线程互斥访问资源.使用互 ...