首页 > 代码库 > Maximum 贪心
Maximum 贪心
Maximum
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescription
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 ( m2000, p12, p is even). Input is correct, i.e. for each input numbers there existsx1, 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
1 #include<stdio.h> 2 #include<string.h> 3 #include<set> 4 #include<math.h> 5 #include<iostream> 6 #include<algorithm> 7 using namespace std; 8 int main() 9 { 10 int m,p,a,b; 11 double ans; 12 while(~scanf("%d%d%d%d",&m,&p,&a,&b)) 13 { 14 if(b<0) 15 b=-b,ans=a*b*pow(sqrt(a*1.0)/a,p),m-=a*b; 16 else ans=b*pow(sqrt(a*1.0),p),m-=b; 17 int rr=m/(a+1); 18 m%=(a+1); 19 m--; 20 ans+=rr*(pow(sqrt(a*1.0),p*1.0)+a*pow(sqrt(a*1.0)/a,p*1.0)); 21 if(m>0){ 22 ans+=m*pow(sqrt(a*1.0)/a,p); 23 ans+=pow(m*sqrt(a*1.0)/a,p); 24 } 25 printf("%.0lf\n",ans); 26 } 27 }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。