• A. Beat The Odds


    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Given a sequence a1,a2,…,ana1,a2,…,an, find the minimum number of elements to remove from the sequence such that after the removal, the sum of every 22 consecutive elements is even.

    Input

    Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. Description of the test cases follows.

    The first line of each test case contains a single integer nn (3≤n≤1053≤n≤105).

    The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — elements of the sequence.

    It is guaranteed that the sum of nn over all test cases does not exceed 105105.

    Output

    For each test case, print a single integer — the minimum number of elements to remove from the sequence such that the sum of every 22 consecutive elements is even.

    Example

    input

    Copy

    2
    5
    2 4 3 6 8
    6
    3 5 9 7 1 3
    

    output

    Copy

    1
    0
    

    Note

    In the first test case, after removing 33, the sequence becomes [2,4,6,8][2,4,6,8]. The pairs of consecutive elements are {[2,4],[4,6],[6,8]}{[2,4],[4,6],[6,8]}. Each consecutive pair has an even sum now. Hence, we only need to remove 11 element to satisfy the condition asked.

    In the second test case, each consecutive pair already has an even sum so we need not remove any element.

    解题说明:水题,要么删除其中所有的奇数、要么删除其中所有的偶数。

    1. #include"stdio.h"
    2. #include"math.h"
    3. int main()
    4. {
    5. int k, b, x;
    6. scanf("%d", &k);
    7. for (int i = 0; i<k; i++)
    8. {
    9. int br = 0;
    10. scanf("%d", &b);
    11. for (int j = 0; j<b; j++)
    12. {
    13. scanf("%d", &x);
    14. if (x % 2 != 0)
    15. {
    16. br++;
    17. }
    18. }
    19. if (br > b - br)
    20. {
    21. printf("%d\n", b - br);
    22. }
    23. else
    24. {
    25. printf("%d\n", br);
    26. }
    27. }
    28. return 0;
    29. }

  • 相关阅读:
    20、Python -- 变量作用域、局部函数
    Mac配置iTerm样式终端
    【Java - L - 0102】- m - 二叉树的层序遍历
    基于window10的远程桌面报错:要求的函数不受支持 的问题解决方法
    @ControllerAdvice
    数据结构:链式队列
    Visual Studio 调试时加载符号慢
    webapck打包原理--启动过程分析
    AspNetCore配置多环境log4net配置文件
    HttpServletRequest详解
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/125452917