Codeforces Round #235 (Div. 2) A. Vanya and Cards
来源:互联网 发布:淘宝找同款 编辑:程序博客网 时间:2024/04/28 00:57
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value.
Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found n of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero?
You can assume that initially Vanya had infinitely many cards with each integer number from - x to x.
The first line contains two integers: n (1 ≤ n ≤ 1000) — the number of found cards and x (1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line contains n space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed x in their absolute value.
Print a single number — the answer to the problem.
3 2-1 1 2
1
2 3-2 -2
2
In the first sample, Vanya needs to find a single card with number -2.
In the second sample, Vanya needs to find two cards with number 2. He can't find a single card with the required number as the numbers on the lost cards do not exceed 3 in their absolute value.
很水的一道题,6分钟A掉
代码如下:
#include <algorithm>#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <vector>#include <map>#define MAXN 1010#define ll long longusing namespace std;int a[MAXN];int main(void){int n;int x;while(cin >> n){cin >> x;int sum = 0;for(int i=0; i<n; ++i){ cin >> a[i]; sum += a[i]; } sum = abs(sum); if(sum%x != 0) cout << sum/x+1 << endl;else cout << sum/x << endl;}return 0;}
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- codeforces round #235 A. Vanya and Cards
- codeforces A. Vanya and Cards
- A. Vanya and Table(Codeforces Round #308 (Div. 2))
- Codeforces Round #308 (Div. 2) A. Vanya and Table
- Codeforces Round #355 (Div. 2) A. Vanya and Fence(水题)
- Codeforces Round #356 (Div. 2) A - Bear and Five Cards
- codeforces 401A - Vanya and Cards
- CodeForces 258A Vanya and Cards
- codeforces 401A Vanya and Cards
- CodeForces 401A Vanya and Cards
- codeforces 401A Vanya and Cards
- Codeforces Round #364 (Div. 2) A. Cards
- Codeforces Round #364 (Div. 2) A. Cards
- codeforces Vanya and Cards
- A. Vanya and Cards
- A. Vanya and Cards
- A. Vanya and Cards
- 方向感应器的获取及使用
- error LNK2019对照表
- 【Web】<template>不解析不渲染,可包含任意元素,可在任意元素之中
- jvm是如何确定一个方法的调用的呢。
- 2014 年 TOP 10 的 PHP 框架
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- 2012年蓝桥杯预赛题-密码发生器
- Servlet 中文乱码问题及解决方案剖析
- 排名前 8 的 PHP 调试工具,你认可吗?
- JAVA基础之泛型应用
- 常用JavaScript
- file类renameTo使用小demo
- codeforces C. Team
- VC6.0使用教程-30分钟玩转Microsoft Visual C++ 6.0