CodeForces 401A Vanya and Cards
来源:互联网 发布:怎么查看数据库ip地址 编辑:程序博客网 时间:2024/04/28 07:35
Vanya and CardsCrawling in process...
Crawling failed Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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 exceedx 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 foundn 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.
Input
The first line contains two integers: n(1 ≤ n ≤ 1000) — the number of found cards andx(1 ≤ x ≤ 1000) — the maximum absolute value of the number on a card. The second line containsn space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceedx in their absolute value.
Output
Print a single number — the answer to the problem.
Sample Input
3 2-1 1 2
1
2 3-2 -2
2
Sample Output
Hint
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.
代码:
#include <iostream>#include <stdio.h>#include <math.h>using namespace std;int main(){ int n,x,m; int sum; while(scanf("%d%d",&n,&x)!=EOF) { sum=0; for(int i=1;i<=n;i++) { scanf("%d",&m); sum+=m; } int ans=fabs(sum)/x; if(sum%x!=0) ans++; cout<<ans<<endl; } return 0;}
- codeforces 401A - Vanya and Cards
- codeforces 401A Vanya and Cards
- CodeForces 401A Vanya and Cards
- codeforces 401A Vanya and Cards
- codeforces A. Vanya and Cards
- Codeforces 401A Vanya and Cards(水题)
- codeforces round #235 A. Vanya and Cards
- CodeForces 258A Vanya and Cards
- codeforces Vanya and Cards
- A. Vanya and Cards
- A. Vanya and Cards
- A. Vanya and Cards
- code forces 401A Vanya and Cards
- Codeforces Round #235 (Div. 2) A. Vanya and Cards
- (CF)A. Vanya and Cards
- Vanya and Cards
- Vanya and Cards
- Vanya and Cards
- Android 编程下 shape 绘制图形
- 用C语言实现对冗余层发送的数据包进行过滤判断处理
- js实现继承的5种方式
- Scala教程(十九)Scala界面GUI编程
- Android处理服务器返回的图片数据
- CodeForces 401A Vanya and Cards
- 编译PROJ4
- Quick-Cocos2d-x 如何入门
- IOS 音频,视频,照相,摄影
- Linux 设置服务器开机启动
- 7种形式的Android Dialog使用举例
- Eclipse中安装Lua Eclipse插件
- 笔记关于自制简单的操作系统 第一弹
- Ehcache 整合Spring 使用页面、对象缓存