当前位置:网站首页>A. Beat The Odds
A. Beat The Odds
2022-06-29 15:36: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.
解题说明:水题,要么删除其中所有的奇数、要么删除其中所有的偶数。
#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;
}
边栏推荐
- 关于 麒麟系统启动应用报错“undefined symbol: __cxa_throw_bad_array_new_length, version Qt_5“ 的解决方法
- File common tool class, stream related application (record)
- Summary of recent work
- Andorid Jetpack Hilt
- Excel中构建SQL语句
- 14.IP协议-bite
- Symfony framework security component firewall configuration
- radar transmitter
- Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
- Rust Basics
猜你喜欢
商业智能BI与业务管理决策思维之三:业务质量分析
PostgreSQL source code learning (24) -- transaction log ⑤ - log writing to wal buffer
架构实战营模块五作业
89.(cesium篇)cesium聚合图(自定义图片)
《网络是怎么样连接的》读书笔记 - 服务器端的局域网中(四)
无意发现的【TiDB缓存表】,竟能解决读写热点问题
Digital tracking analysis of insurance services in the first quarter of 2022
C#学习一:值类型与引用类型
攻防演练之战前扫雷:漏洞管理的5大措施
What are the advantages of intelligent chat robots? Senior independent station sellers tell you!
随机推荐
12.UDP协议-bite
PWM to 0-5v/0-10v/1-5v linear signal transmitter
绑定证券账户到同花顺安全吗?哪家券商开户后可以绑定同花顺
89.(cesium篇)cesium聚合图(自定义图片)
《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(五)
2022-06-29日报: 李飞飞划重点的「具身智能」,走到哪一步了?
Introduction to radar related contents
File common tool class, stream related application (record)
Mysql database naming conventions PDF
Detailed explanation of list set
Taro中添加小程序 “lazyCodeLoading“: “requiredComponents“,
kotlin 注解聲明與使用
作为开发人员,无代码开发平台 iVX 你有必要了解一下
14.IP协议-bite
架构实战营模块五作业
Google software version experience cycle
Three development trends of enterprise application viewed from the third technological revolution
swift JSONSerialization
LeetCode-64-最小路径和
el-table-column行按钮防重控制loading