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轴为一个线段.问题转换成用最少 ...
随机推荐
- web前端开发常用工具
http://www.gbin1.com/technology/javautilities/20120806-resource-for-front-end-developer/ 冒泡样式 http:/ ...
- (1)html初步--表格的使用
用表格标签制作简历 html代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " ...
- 【Python】iichats —— 命令行下的局域网聊天程序
转载请声明出处:http://www.cnblogs.com/kevince/p/3941728.html ——By Kevince ii系列工具第三弹,命令行下的局域网聊天程序 原理: 程序启动 ...
- Hibernate、批量操作数据
Hibernate 批量操作数据可以使用两种方法实现 1.分批更新,每一小批同步一次数据: public void saveEmployee2(){ Session s=HibernateSessio ...
- div简单布局理解
以下是div的理解
- SPFA,dijskra,prime,topu四种算法的模板
////#include<stdio.h> ////#include<string.h> ////#include<queue> ////#include<a ...
- Java面试题之谈谈你对Struts的理解
1. struts是一个按MVC模式设计的Web层框架,其实它就是一个大大的servlet,这个Servlet名为ActionServlet,或是ActionServlet的子类.我们可以在web.x ...
- 浅谈Oracle数据库性能优化的目标
Oracle性能优化保证了Oracle数据库的健壮性,为了保证Oracle数据库运行在最佳的性能状态下,在信息系统开发之前就应该考虑数据库的优化策略.从数据库性能优化的场景来区分,可以将性能优化分为如 ...
- EC读书笔记系列之9:条款16、17
条款16 成对使用new和delete时要采取相同形式 记住: ★若你在new表达式中使用[ ],必须在相应的delete中也使用[ ],反之亦然 -------------------------- ...
- C/C++输入输出
一. cin>>当碰到空格或换行符'\n'时,输入结束 该操作符是根据后面变量的类型读取数据. 输入结束条件 :遇到Enter.Space.Tab键. 对结束符的处理 :丢弃缓冲区中使得输 ...