Maximum 贪心

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

Submit Status

Description

Let x1x2,..., 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: mpab ( m2000, p12, p 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\n",ans);
26 }
27 }

Maximum 贪心,码迷,mamicode.com

时间: 2024-11-08 18:07:43

Maximum 贪心的相关文章

CF169D2 D – Little Girl and Maximum XOR 贪心

解题思路: 经过打表可得规律答案要么是0 要么是2的N次 要得到最大的XOR值,其值一定是2的N次 即在 l 和 r 的二进制中,从左到右遍历过去,如果碰到 l 为 1 r 为 0 则可说明在『l , r]中存在 1000000000 和 0111111111 可得到最大XOR值为2的N次 PS:不会存在首先出现 l 为 0 r 为 1 的情况,因为 l < r #include<stdio.h> #include<math.h> int main(){ long long

D. Little Girl and Maximum XOR(贪心)

D. Little Girl and Maximum XOR A little girl loves problems on bitwise operations very much. Here's one of them. You are given two integers l and r. Let's consider the values of for all pairs of integers a and b (l?≤?a?≤?b?≤?r). Your task is to find

Codeforces Round #169 (Div. 2)---C. Little Girl and Maximum Sum(简单贪心)

The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of n elements (the elements of the array are indexed starting from 1); also, there are q queries, each one is defi

CodeForces 276D – Little Girl and Maximum XOR 贪心

整整10个月后第二次搞这个问题才搞懂........第一次还是太随意了. 解题思路: 经过打表可得规律答案要么是0 要么是2的N次 - 1 要得到最大的XOR值,其值一定是2的N次 - 1 即在 l 和 r 的二进制中,从左到右遍历过去,如果碰到 (2 ^ i) & l 为 1 , (2 ^ i) & r 为 0 即在 l 和 r 之间一定存在 形如 10+ 和01+这样的数. 则可说明在[l , r]中存在 1000000000 和 0111111111 可得到最大XOR值为2的N次 -

【推理,贪心】UVa 1319 - Maximum

看到了大神的代码.理解了好久...真是差距. 题意:给出m, p, a, b,然后xi满足已下两个公式, 求 xp1 + xp2 +...+ xpm 的最大值. 1.-1/sqrt(a) <= xi <= sqrt(a); (a>0) 2.x1+x2+...+xm = b*sqrt(a); 注意:p为偶数. 解题思路:因为p为偶数,所以sqrt(a)和-1/sqrt(a)的p次方都为正数且sqrt(a) > 1/sqrt(a).所以贪心思想时尽量先取sqrt(a);当已经取的xi的

hdu 6047 Maximum Sequence(贪心)

Description Steph is extremely obsessed with "sequence problems" that are usually seen on magazines: Given the sequence 11, 23, 30, 35, what is the next number? Steph always finds them too easy for such a genius like himself until one day Klay c

HDU 6047 Maximum Sequence (贪心+单调队列)

题意:给定一个序列,让你构造出一个序列,满足条件,且最大.条件是 选取一个ai <= max{a[b[j], j]-j} 析:贪心,贪心策略就是先尽量产生大的,所以就是对于B序列尽量从头开始,由于数据比较大,采用桶排序,然后维护一个单调队列,使得最头上最大. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #i

HDU 6047 Maximum Sequence(贪心+线段树)

题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=6047 题目: Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 90    Accepted Submission(s): 44 Problem Description Steph is extremely o

UVA - 108 - Maximum Sum (简单贪心)

UVA - 108 Maximum Sum Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Background A problem that is simple to solve in one dimension is often much more difficult to solve in more than one dimension.