POJ 2209 The King(我的水题之路——n次方之和)
来源:互联网 发布:屏幕文字抓取软件 编辑:程序博客网 时间:2024/05/16 19:32
The King
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 5223 Accepted: 2906
Description
Once upon a time in a country far away lived a king and he had a big kingdom. He was a very clever king but he had one weakness -- he could count only up to three.
Nevertheless, he did not consider this to be a really great drawback, since he had a lot of wizards who could count up to one hundred (and some of them, people said, even up to one thousand), so it was all right. But one day the grief came to the kingdom as the outnumbering barbarians started to approach from all sides. And the king then had to make the most important decision in his life. He had to choose which of his sons to make generals that he would send to the borders of the country to lead the army.
However, the king knew that though some of his sons were clever, just like he was, some of them were quite stupid and could only lower army spirits with their wrong decisions. More precisely, he knew about each of his sons his mental potential -- an integer number ranging from minus three to three (remember, that the king could count only up to three). He also knew that the chance of his army defeating barbarians was proportional to the sum of some powers of mental potentials of those of his sons that he would make generals (the power exponent was a positive integer number, the same for all his sons and not exceeding three either). Thus he had to choose such a combination of his sons to lead
the army, that this sum would be maximal possible.
However, the king himself could not make all apropriate calculations since, for example, the second power of the number not exceeding three (which is its square) could be greater than three, and therefore he asked you, his most intellegent wizard, to solve this problem.
Nevertheless, he did not consider this to be a really great drawback, since he had a lot of wizards who could count up to one hundred (and some of them, people said, even up to one thousand), so it was all right. But one day the grief came to the kingdom as the outnumbering barbarians started to approach from all sides. And the king then had to make the most important decision in his life. He had to choose which of his sons to make generals that he would send to the borders of the country to lead the army.
However, the king knew that though some of his sons were clever, just like he was, some of them were quite stupid and could only lower army spirits with their wrong decisions. More precisely, he knew about each of his sons his mental potential -- an integer number ranging from minus three to three (remember, that the king could count only up to three). He also knew that the chance of his army defeating barbarians was proportional to the sum of some powers of mental potentials of those of his sons that he would make generals (the power exponent was a positive integer number, the same for all his sons and not exceeding three either). Thus he had to choose such a combination of his sons to lead
the army, that this sum would be maximal possible.
However, the king himself could not make all apropriate calculations since, for example, the second power of the number not exceeding three (which is its square) could be greater than three, and therefore he asked you, his most intellegent wizard, to solve this problem.
Input
The first line of the input file contains the number of the sons of the king (integer number less or equal to one hundred). The second line contains the positive integer number not exceeding three, the exponent in the formula used to calculate the chance of defeating barbarians. The third line contains the list of mental potentials of king’s sons -- all integer numbers, not greater than three by their absolute value.
Output
Output the only number -- the maximal possible chance of defeating barbarians measured as the sum described.
Sample Input
332 -1 1
Sample Output
9
Hint
In the example above the king should choose his first and third sons to be the generals. In this case the chance to defeat barbarians, which is the sum of cubes of mental potentials of these sons, is eight plus one, that is nine.
Source
Northeastern Europe 2002, Northern Subregion
有n个数字,对于每一个数字取m次方,如果其值大于0就相加取和,否则不用处理。
注意点:
1)double型不能用于%.0lf输出,否则报错(1WA).
代码(1AC 1WA):
#include <cstdio>#include <cstdlib>#include <cmath>int main(void){ int n, m, t; int sum, tmp; int i; while (scanf("%d", &n) != EOF){ scanf("%d", &m); for (sum = i = 0; i < n; i++){ scanf("%d", &t); tmp = pow(t, m); if (tmp > 0){ sum += tmp; } } printf("%d\n", sum); } return 0;}
- POJ 2209 The King(我的水题之路——n次方之和)
- POJ 2301 Beat the Spread!(我的水题之路——两数之和、两数之差)
- POJ 1528 Perfection(我的水题之路——因子之和)
- POJ 2128 Highways(我的水题之路——最小两条公路之和)
- POJ 2909 Goldbach's Conjecture(我的水题之路——任一数为素数对之和)
- POJ 1207 The 3n+1 problem(我的水题之路——输入输出要保持原有顺序)
- POJ 3100 Root of the Problem(我的水题之路——取A^N最接近B的A)
- POJ 2209 The King(水~)
- POJ 2209 The King
- poj 2209 The King
- poj 2209 The King
- poj 2209 The King
- POJ 2163 Easy Trading(我的水题之路——数组阶段n m的平均值比较)
- POJ 3438 Look and Say(我的水题之路——N个M的队列)
- POJ 2109 Power of Cryptography(我的水题之路——k^n=p)
- POJ 2000 Glod Conins(我的水题之路——之后的N天N个金币,打表)
- POJ 1298 The Hardest Problem Ever(我的水题之路——解密,水题)
- POJ 2070 Filling Out the Team(我的水题之路——double比较)
- JavaMail接收邮件和附件 (测试可用)
- 如何在eclipse里自动生成带@author字样的注释
- 使用npm制作nodejs模块包
- DJANGO站点搭建
- 网页制作的日志或留言模块的制作 fckeditor~(转载)
- POJ 2209 The King(我的水题之路——n次方之和)
- Dynamics CRM 2011 编程系列(1):开发环境的搭建
- linux 下的时间函数整理
- java线程安全总结
- 判断二进制数中的1有奇数个还是偶数个
- 为什么Java多线程需要同步?
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- document.body和document.documentElement的区别
- Android学习笔记之ExpandableListView