当前位置:网站首页>A. Beat The Odds
A. Beat The Odds
2022-06-29 21:35:00 【Felven】
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.
Problem solving instructions : Water problem , Or delete all the odd numbers 、 Or delete all even numbers .
#include"stdio.h"
#include"math.h"
int main()
{
int k, b, x;
scanf("%d", &k);
for (int i = 0; i<k; i++)
{
int br = 0;
scanf("%d", &b);
for (int j = 0; j<b; j++)
{
scanf("%d", &x);
if (x % 2 != 0)
{
br++;
}
}
if (br > b - br)
{
printf("%d\n", b - br);
}
else
{
printf("%d\n", br);
}
}
return 0;
}边栏推荐
- Getting started with completabilefuture
- What is unique about MES system?
- Alibaba product details API interface (item_get- get product details interface), Alibaba API interface
- 如何从外表判断导电滑环的质量
- leetcode:238. 除自身以外数组的乘积
- Exit operation in project
- [fishing artifact] code tool for lowering the seconds of UI Library -- form part (I) design
- THREEJS基础入门
- How to integrate MES system with ERP? This article tells you the answer
- flutter BottomNavigationBar切换页面保持状态
猜你喜欢

About Effect Size

Exit operation in project

A new Polaris has risen!

不同系统下的文件层级符号小结

Yolov6 training your own data record +yolov5 comparison test

Explain PBR texture maps

THREEJS基础入门

Win10添加ssh公钥

Win10 sets automatic dial-up networking task to realize automatic reconnection after startup and disconnection

报表交付工程师
随机推荐
空间导电盘式滑环材料的选择
如何评价科大讯飞AI翻译笔P20系列,值得买吗?
Goahead translation - Active Server Pages
leetcode:307. 区域和检索 - 数组可修改
双目立体视觉摄像头的标定、矫正、世界坐标计算(opencv)
Sophon CE community edition goes online, and free get is a lightweight, easy-to-use, efficient and intelligent data analysis tool
报表交付工程师
How to evaluate iFLYTEK AI translation pen P20 series? Is it worth buying?
Common methods of string class
Threejs basic introduction
【ROS进阶篇】第四讲 ROS中的重名问题(节点、话题与参数)
Layer 3 loop brought by route Summary - solution experiment
Star ring technology data security management platform defender heavy release
【云原生实战】KubeSphere实战——多租户系统实战
不同系统下的文件层级符号小结
实现inotify配合rsync实时备份
Topic39——78. 子集
leetcode:724. 寻找数组的中心下标
TMUX settings
Jump to open a new window