SGU 163.Wise King

一道题目长的水题。。。。

总结就一句话,给出n个(-3~3)的数,一个数m,取任意个数是使这些数的m次幂之和最大。

code

#include <iostream>
#include <cmath>
using namespace std;
int n, m, x;
int g[7];
int main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) cin >> x, g[x + 3]++;
	int ans = 0;
	for (int i = 0; i <= 6; i++) {
		int tem = int (pow (i - 3, m) );
		if (tem > 0) ans += tem*g[i];
	}
	cout<<ans;
	return 0;
}

  

SGU 163.Wise King

时间: 2024-10-06 23:37:52

SGU 163.Wise King的相关文章

sgu100~199题解

老东西了..发上来吧.. Sgu题解系列  南开中学邹事成 100:A+B略 101:Domino 给n块多米诺骨牌,每张骨牌两端各有从1到6的一个数字,现在要把这些骨牌排成一列,使相邻的两块骨牌相对的面所写的数字一样. 可以把每一块多米诺骨牌想象成一条边,把面上写的数字抽象成点,比如一块骨牌正面写的1反面写的2就想象成连了一条从1到2的边,那么这就是求一条有重边的欧拉回路了,dfs一下即可. 102:Coprimes给定n求从1到n中与n互质的数的个数. 可以把n质因数分解后直接代入欧拉函数.

No Game No Life

The world has finally bugged out. — Shiro and Sora Throughout all of history, no wise king has ever forced his army to obey him through oppression. People will only truly fight for what is right. And there is only one thing that is truly right in thi

学习 swift (1)

https://developer.apple.com/library/prerelease/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/Lesson1.html#//apple_ref/doc/uid/TP40015214-CH3-SW1 这个链接里面介绍的 swift 的语法大部分都很容易理解.对于部分特别的地方做下记录 Structures support many of the same behaviors as cla

SGU 298 King Berl VI 差分约束 并使得min(dis[n]-dis[1])

题目链接:点击打开链接 题意: 给定n个点m条约束. 下面输出 u v x 表示: dis[u] - dis[v] >= x 然后建图就是 u->v 边权为-x 输出一个解满足 -10000<= dis[i] <= 10000. 若有多解输出一个 dis[n] - dis[1] 最小的解. 思路: 正图求个最大解,反图求个最小解. 对于一个点的 最大解<最小解,则差分约束无解. 题目要求dis[n]-dis[1]最小,那就令dis[n]为其最小解,dis[1]为其最大解,再s

SGU 438 The Glorious Karlutka River =) 拆点+动态流+最大流

The Glorious Karlutka River =) Time Limit:500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice SGU 438 Appoint description: Description A group of Mtourists are walking along the Karlutka river. They want to cross

SGU[347] Join the Strings

Description 描述 His Royal Highness King of Berland Berl XV was a very wise man and had a very accomplished wife, who was aware of the fact, that prominent and outstanding personalities once having written down their names on the pages of glorious Hist

SGU 220~229

SB题一堆,以后为了提高效率,SB题,一眼题一律不码. 220 Little Bishops 题意:求n*n的棋盘上放K个象的放法, 象可以对角线相互攻击 sb题. 221 Big Bishops 如上,一字未变,加个高精度即可,尼玛我现在高精度都能写错,还是滚回pj吧.. 222. Little Rooks 题意:n*n放车,问方案数.n最大10. 尼玛,真的滚回pj组了!?老子还是读过书的. 223 Little King 题意:如上,把车改成王. 状压直接上. 224. Little Qu

sgu 463 - Walking around Berhattan

K - Walking around Berhattan Time Limit:250MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice SGU 463 Description As you probably know, Berhattan is a district of Berland's largest city and it consists of equal squar

hdu-5643 King&#39;s Game(打表)

题目链接: King's Game Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 200    Accepted Submission(s): 115 Problem Description In order to remember history, King plans to play losephus problem in the