POJ 2209 The King(简单贪心)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 7499 | Accepted: 4060 |
Description
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
Output
Sample Input
3
3
2 -1 1
Sample Output
9
Hint
Source
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n,m;
int a[];
int b[];
while(scanf("%d",&n)!=EOF)
{
scanf("%d",&m);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int sum=,ans=;
for(int i=;i<n;i++)
{
for(int j=;j<=m;j++)
sum*=a[i];
if(sum>)
ans+=sum;
sum=;
}
printf("%d\n",ans);
}
return ;
}
POJ 2209 The King(简单贪心)的更多相关文章
- POJ 2209 The King#贪心
(- ̄▽ ̄)-* 水 //水题:潜力^e为正数(e为2时都可以)的儿子都可以去上战场了, //英文要看懂,exponent指数,不超过3的正数 #include<iostream> #i ...
- CF 628C --- Bear and String Distance --- 简单贪心
CF 628C 题目大意:给定一个长度为n(n < 10^5)的只含小写字母的字符串,以及一个数d,定义字符的dis--dis(ch1, ch2)为两个字符之差, 两个串的dis为各个位置上字符 ...
- Uva 11729 Commando War (简单贪心)
Uva 11729 Commando War (简单贪心) There is a war and it doesn't look very promising for your country. N ...
- CDOJ 1502 string(简单贪心)
题目大意:原题链接 相邻两个字母如果不同,则可以结合为前一个字母,如ac可结合为a.现给定一个字符串,问结合后最短可以剩下多少个字符串 解体思路:简单贪心 一开始读题时,就联想到之前做过的一道题,从后 ...
- ACM_发工资(简单贪心)
发工资咯: Time Limit: 2000/1000ms (Java/Others) Problem Description: 作为广财大的老师,最盼望的日子就是每月的8号了,因为这一天是发工资的日 ...
- ACM_Ruin of Titanic(简单贪心)
Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...
- poj 1328 Radar Installation (简单的贪心)
Radar Installation Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 42925 Accepted: 94 ...
- POJ 2370 Democracy in danger(简单贪心)
Democracy in danger Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3388 Accepted: 25 ...
- POJ 2260 Error Correction 模拟 贪心 简单题
Error Correction Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6825 Accepted: 4289 ...
随机推荐
- 安装cocoa pods时出现Operation not permitted - /usr/bin/xcodeproj的问题
安装cocoa pods时, 在命令行中输入: 安装:sudo gem install cocoapods报Operation not permitted - /usr/bin/xcodeproj这个 ...
- 监听键盘弹起View上调
可以用三方库IQKeyboardManager 用这个第三方 http://www.jianshu.com/p/f8157895 #pragma mark - keyboard events - // ...
- htpasswd 命令详解
htpasswd参数 -c 创建passwdfile.如果passwdfile 已经存在,那么它会重新写入并删去原有内容. -n 不更新passwordfile,直接显示密码 -m 使用MD5加密(默 ...
- 三菱Q系列PLC的io分配
1.系统基本配置 2.存储卡配置 3.外部IO标号 4.主基板IO模块的IO号分配 5.扩展基板IO口标号 6.标准配置实例 7. 一.输入采样阶段 在输入采样阶段,可编程逻辑控制器以扫描方式依次地读 ...
- ArcGIS API for JavaScript 4.2学习笔记[10] 2D添加指北针widget、视图保存、视图padding(第二章完结)
这几个例子是第二章除了入门之外比较简单的几个,就做个合集,把最核心的代码(第二参数)和 引用放上来即可,不作多解释. 2D地图添加指北针widget 2D地图一般修正方向为正北方就需要这个widget ...
- Centos7解决图形界面卡死问题
经常会遇到图形界面卡死,搜了一搜,解决办法如下: killall -9 gnome-shell
- ubuntu12.04 安装中文输入法
1. 安装输入法的第一步,是安装语言包.我们选择System Settings-->Language Support-->Install/Remove Languages 选择中文 2. ...
- ASP.NET MVC框架开发系列教程
本系列教程是自己在工作中使用到而记录的,如有错误之处,请给与指正 文章目录 MVC4 开篇 第一章 初识MVC4 第二章 下山遇虎(@helper) 第三章 Models模块属性详解 第四章 在MVC ...
- 析构函数(C#)
析构函数又称终结器,用于析构类的实例. 定义 析构函数(destructor) 与构造函数相反,当对象结束其生命周期时(例如对象所在的函数已调用完毕),系统自动执行析构函数.析构函数往往用来做&quo ...
- TurnipBit开发板DIY呼吸的吃豆人教程实例
转载请以链接形式注明文章来源(MicroPythonQQ技术交流群:157816561,公众号:MicroPython玩家汇) 0x00前言 吃豆人是耳熟能详的可爱形象,如今我们的TurnipBit也 ...