LA 2911Maximum poj 3066
来源:互联网 发布:nodejs工程师 知乎 编辑:程序博客网 时间:2024/05/27 00:45
原题:(注意uva la上面的题目描述有错误!!)
Let x1, x2, …, xm be real numbers satisfying the following conditions:
for some integers a and b (a > 0).
Determine the maximum value of x1^p + x2^p + … + xm^p 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.
Sample Input
1997 12 3 -318
10 2 4 -1
Sample Output
189548
6
中文:
给你m,p,a,b,而且满足图中的两个式子,问你x1^p + x2^p + … + xm^p 最小是多少?
//#include <bits/stdc++.h>#include<iostream>#include<cmath>using namespace std;int main(){ ios::sync_with_stdio(false); double m,p,a,b,ans; while(cin>>m>>p>>a>>b) { double x=sqrt(a); double y=-1/x; double ab=a*b; int xx=0,yy=0; for(int i=0;i<m-1;i++) { if(ab>=x) { ab-=a; xx++; } else { ab+=1; yy++; } } ans=xx*pow(x,p)+yy*pow(y,p)+pow(ab/x,p); cout<<(int)(ans+0.5)<<endl; } return 0;}
解答:
这题坑了我一下午的时间,首先uva上面的题目描述有错误!!!
研究了半天,是在不知道是咋回事,看别人的解题报告。了解题的大概意思,结果还是卡住了,呵呵。
思路很简单,既然是让你找最后式子的最大值,而且p是一个偶数,那么就让xi尽量取根号a即可。不过程序不能简单粗暴的写,否则会过不去。计算取多少个根号a要用循环的减去,这样才能满足精度要求。
- LA 2911Maximum poj 3066
- UVa Live Archive 2911 & POJ 3066 - Maximum
- poj 3066 Maximum 贪心
- POJ 3066 Maximum 笔记
- Poj 3154(LA 3708)
- poj 1287 && la 2515
- poj 2479 Maximum sum
- POJ 2479 Maximum sum
- POJ 2479 Maximum sum
- Maximum repetition substring POJ
- POJ 2479 Maximum sum
- poj 2479 Maximum sum
- Poj 2479 Maximum sum
- POJ-2479-Maximum sum
- POJ 2479 Maximum sum
- poj 2479 Maximum sum
- poj 2479 Maximum sum
- poj 2479 Maximum sum
- iOS-68-星星评价、显示小数点星星评价效果(附demo)
- 前端框架之Semantic UI
- 【杭电oj2040】亲和数
- 模拟题2(打表)
- 【算法】KMP经典算法,你真的懂了吗?
- LA 2911Maximum poj 3066
- 【游戏后端】游戏服务器端开发的一些建议(转载)
- bzoj 2763 JLOI 2011 飞行路线 分层图+spfa
- 二叉树的遍历思想及核心代码实现
- 新的开始
- ButterKnife框架
- 金蝶笔试总结
- Java_abstract类
- oracel copy 数据报错