UVALive - 2911 Maximum
来源:互联网 发布:vv51软件下载 编辑:程序博客网 时间:2024/06/16 11:50
题目大意:给定 m, p, a, b. 根据题目中的两个条件.求出的 xp1 + xp2 +...+ xpm 最大值.
解题思路: 贪心, 由于题目明确了 p 是偶数, 所以 x 绝对值越大的时候 x^p 值越大. 然后我们根据条件,发现 x 尽可能取 sqrt(a) 是最好的, 但是不一定能全部取得 sqrt(a), 那么多出来的还要拿一部分去抵消。这时候我们就用 -1/sqrt(a) 去抵消是最好的, 这样就能满足最大了, 不过要注意, 抵消到最后剩下那部分也要考虑进去
#include <cstdio>#include <cmath>int main() {int m, p, a, b;while (scanf("%d%d%d%d", &m, &p, &a, &b) != EOF) {int temp = a * b, cnt = 0;double num = pow(sqrt(a), p);for (int i = 1; i < m; i++)temp < a ? temp++, cnt++ : temp -= a;printf("%d\n",int((m-1-cnt)*num + cnt/num + pow(temp/sqrt(a), p) + 0.5));}return 0;}
0 0
- UVAlive 2911 Maximum(贪心)
- UVALive - 2911 Maximum
- UVALive - 2911 Maximum
- UVALive - 2911 Maximum
- UVALive 2911 Maximum
- UVALive 2911 Maximum
- UVALive 6926Maximum Score(组合数学)
- UVALive 6175 Maximum Random Walk 期望+概率dp
- uvalive 2911(贪心)
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- UVALive
- MP3文件结构及解码概述
- 每日get一个新命令
- 优惠劵收集问题
- 设计模式---------适配器模式
- TCP/IP、Http、Socket的区别
- UVALive - 2911 Maximum
- C++函数指针的定义
- httpd: Could not reliably determine the server's fully qualified domain name
- Android 中 的adapter优化问题
- 数据结构&&平衡二叉树
- 【Leetcode】Reverse Words in a String JAVA
- QCA4004开发板之使用
- Windows Server 2008远程连接桌面黑屏解决方法
- Android的Handler总结