• 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. }

  • 相关阅读:
    泡咖啡问题
    并发编程之并发理论篇--内存模型
    【项目搭建】SpringBoot多模块项目搭建
    Temporal线上部署
    【面试题】 vue高频面试知识点汇总【2022寒冬版】
    企业电子招投标采购系统源码之电子招投标的组成
    user-agent怎么获取
    数据结构:单链表
    行业专网对比公网,优势在哪儿?能满足什么特定要求?
    人工智能知识全面讲解:特征工程
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/125452917