UVAlive 2911 Maximum(贪心)
Let x1, x2,..., 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: m, p, a, b ( m
2000, p
12, p is even). Input is correct, i.e. for each input numbers there exists x1, x2,..., 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(贪心)的更多相关文章
- uvalive 2911 Maximum(贪心)
题目连接:2911 - Maximum 题目大意:给出m, p, a, b,然后xi满足题目中的两个公式, 要求求的 xp1 + xp2 +...+ xpm 的最大值. 解题思路:可以将x1 + x2 ...
- UVALive 4867 Maximum Square 贪心
E - Maximum Square Time Limit:4500MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- Maximum 贪心
Maximum Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Des ...
- UVALive - 4225(贪心)
题目链接:https://vjudge.net/contest/244167#problem/F 题目: Given any integer base b ≥ 2, it is well known ...
- UVALive 4850 Installations 贪心
题目链接 题意 工程师要安装n个服务,其中服务Ji需要si单位的安装时间,截止时间为di.超时会有惩罚值,若实际完成时间为ci,则惩罚值为max{0,ci-di}.从0时刻开始执行任务,问惩罚值最大 ...
- UVALive 4863 Balloons 贪心/费用流
There will be several test cases in the input. Each test case will begin with a line with three inte ...
- UVALive - 6268 Cycling 贪心
UVALive - 6268 Cycling 题意:从一端走到另一端,有T个红绿灯,告诉你红绿灯的持续时间,求最短的到达终点的时间.x 思路:
- UVALive 4731 dp+贪心
这个题首先要利用题目的特性,先贪心,否则无法进行DP 因为求期望的话,越后面的乘的越大,所以为了得到最小值,应该把概率值降序排序,把大的数跟小的系数相乘 然后这种dp的特性就是转移的时候,由 i推到i ...
- UVALive 3835:Highway(贪心 Grade D)
VJ题目链接 题意:平面上有n个点,在x轴上放一些点,使得平面上所有点都能找到某个x轴上的点,使得他们的距离小于d.求最少放几个点. 思路:以点为中心作半径为d的圆,交x轴为一个线段.问题转换成用最少 ...
随机推荐
- (译)iPhone: 用公开API创建带小数点的数字键盘 (OS 3.0, OS 4.0)
(译)iPhone: 用公开API创建带小数点的数字键盘 (OS 3.0, OS 4.0) 更新:ios4.1现在已经将这个做到SDK了.你可以设置键盘类型为UIKeyboardTypeDecimal ...
- #include <time.h>
1 _strtime 2 difftime 3 srand 4 time 1 _strtime 函数简介 函数名: _strtime 头文件: time.h 函数原型: char * _strtime ...
- Android快捷支付SDK Demo resultStatus={4001};memo={參数错误};result={}问题
在支付宝中粘贴RSA公钥并提交,然后问题就完美攻克了...
- C#复制数据库,将数据库数据转到还有一个数据库
本文章以一个表为例,要转多个表则可将DataSet关联多个表.以下给出完整代码.包含引用以及main函数与复制函数. 要说明的是,必须先用Sql语句复制表结构,才干顺利的使用下面代码复制数据. usi ...
- javaScript 工作必知(三) String .的方法从何而来?
String 我们知道javascript 包括:number,string,boolean,null,undefined 基本类型和Object 类型. 在我的认知中,方法属性应该是对象才可以具有的 ...
- Mvc4.0 提取 Cookie 里的东西
/// <summary> /// 提取Cookie /// </summary> /// <returns></returns> public sta ...
- Xcode常用快捷键 (转载)
Xcode快捷键,工欲善其事,必先利其器.mac的键盘和ms的还是有些不一样,得适应一下下. 新建项目 command+shift+n 新建文件 command+n 新建空文件 command+con ...
- Struts2返回Json数据(使用Struts2插件)
这篇我将介绍如何使用Struts2的struts2-json-plugin.jar插件返回JSON数据. 一.其中主要步骤有: 1.将struts2-json-plugin.jar插件拷贝到项目的&q ...
- 浅谈C中的指针和数组(一)
本文转载地址:http://www.cnblogs.com/dolphin0520/archive/2011/11/09/2242138.html 在原文的基础上加入自己的想法作为修改. 指针是C/C ...
- Constructor JavaScript构造器模式。
构造器模式 : Constructor模式中, 通过在构造器前面加 new 关键字, 告诉JavaScript 像使用构造器一样实例化一个新对象,并且对象成员由该函数定义. 构造器内, 使用this ...