zoukankan      html  css  js  c++  java
  • Maximum 贪心

    Maximum
    Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu
    Submit Status

    Description

    Download as PDF
     

    Let x1x2,..., xm be real numbers satisfying the following conditions:

    a)
    -$ {frac{{1}}{{sqrt{a}}}}$$ le$xi$ le$$ sqrt{{5}}$ ;
    b)
    x1 + x2 +...+ xm = b * $ sqrt{{a}}$ 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: mpab ( m$ le$2000, p$ le$12p is even). Input is correct, i.e. for each input numbers there existsx1x2,..., 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
    ",ans);
    26     }
    27 }
    View Code
  • 相关阅读:
    linux基础
    模块三、企业实战案例
    模块二、shell脚本逻辑结构
    模块一:shell 脚本基础
    三剑客、shell脚本
    定时任务、用户管理、磁盘介绍
    python笔记03
    文件属性、正则表达式、文件权限
    Linux系统目录结构介绍
    Linux基础及入门介绍
  • 原文地址:https://www.cnblogs.com/ERKE/p/3701057.html
Copyright © 2011-2022 走看看