`
阿尔萨斯
  • 浏览: 4204241 次
社区版块
存档分类
最新评论

Codeforces 401A Vanya and Cards(水题)

 
阅读更多

题目链接:Codeforces 401A Vanya and Cards


题目大意:给出n和x,表示说有n张卡片,每张卡片上有一个值,绝对值不大于x,现在给出n张卡片上的值,问说至少再拿几张卡片,可以使得所有卡片上值的和等于0.


解题思路:水题,读入的时候计算和,然后取绝对值取整x(尽量用大的牌),如果取整后有余数,要加1.


#include <stdio.h>
#include <stdlib.h>

int main () {
	int n, x, a, s = 0;
	scanf("%d%d", &n, &x);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		s += a;
	}
	s = abs(s);
	printf("%d\n", s/x + (s%x ? 1 : 0));
	return 0;
}



分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics