zoukankan      html  css  js  c++  java
  • codeforces 235 div2 A. Vanya and Cards

    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.

    Input

    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.

    Output

    Print a single number — the answer to the problem.

    Sample test(s)
    Input
    3 2 -1 1 2
    Output
    1
    Input
    2 3 -2 -2
    Output
    2
    Note

    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.

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<algorithm>
     5 using namespace std;
     6 
     7 int main()
     8 {
     9     int n,x;
    10     while(scanf("%d%d",&n,&x)!=EOF)
    11     {
    12         int sum = 0,d;
    13         for(int i = 1;i <= n;++i)
    14         {
    15             scanf("%d",&d);
    16             sum += d;
    17         }
    18         sum = abs(sum);
    19         int ans = (sum % x == 0? sum / x:sum / x + 1);
    20         printf("%d
    ",ans);
    21     }
    22     return 0;
    23 }
    View Code
  • 相关阅读:
    copy深浅拷贝
    def函数
    内置函数
    for / while 循环
    报告的实现
    运行用例
    集合获取依赖用例
    解决依赖关系(单层和递归两种方式)、获取依赖用例去运行
    接口测试平台开发之接口开发(用例集合)
    接口测试平台开发之接口开发(项目管理、接口管理、用例管理)
  • 原文地址:https://www.cnblogs.com/xiaxiaosheng/p/3597254.html
Copyright © 2011-2022 走看看