当前位置:网站首页>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;
}边栏推荐
- CVPR 2022 | 大幅减少零样本学习所需的人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入
- It is expected to significantly improve the computational performance of integrated photonic circuits. The Tsinghua team proposed a diffraction pattern neural network framework
- 攻防演练之战前扫雷:漏洞管理的5大措施
- Training mode of deep learning network
- "Game engine shallow in shallow out" 98 Substancepainer plug-in development
- LeetCode-234-回文链表
- 【云原生】Nacos-TaskManager 任务管理的使用
- Where has lifeifei reached in his key "embodied intelligence"?
- 动作捕捉系统用于苹果采摘机器人
- 14.ip protocol -bite
猜你喜欢

商业智能BI与业务管理决策思维之三:业务质量分析

作为开发人员,无代码开发平台 iVX 你有必要了解一下

Mingdeyang xilinx-k7-325t/410t core board data manual

Classe d'outils commune de fichier, application liée au flux (enregistrement)

Leetcode-234-palindrome linked list

关于 麒麟系统启动应用报错“undefined symbol: __cxa_throw_bad_array_new_length, version Qt_5“ 的解决方法

无意发现的【TiDB缓存表】,竟能解决读写热点问题

天谋科技 Timecho 完成近亿元人民币天使轮融资,围绕 Apache IoTDB 打造工业物联网原生时序数据库

STM32与GD32笔记

12.UDP协议-bite
随机推荐
动作捕捉系统用于苹果采摘机器人
It is expected to significantly improve the computational performance of integrated photonic circuits. The Tsinghua team proposed a diffraction pattern neural network framework
Basic composition of radar
Taro2.* 小程序配置分享微信朋友圈
面试官:说一下MySQL事务隔离级别?
Google 软件版本经历周期
Stlink troubleshooting
12.UDP协议-bite
微信公告号自动回复使用图灵机器人实现智能回复
Polarimetric SAR surface classification
The way of enterprise transformation and upgrading: digital transformation, thinking first
Interviewer: tell me about the MySQL transaction isolation level?
Leetcode notes: Weekly contest 299
天谋科技 Timecho 完成近亿元人民币天使轮融资,围绕 Apache IoTDB 打造工业物联网原生时序数据库
商业智能BI与业务管理决策思维之三:业务质量分析
Symfony framework security component firewall configuration
C语言大作业——匹配系统
Rust Basics
CVPR 2022 | 大幅减少零样本学习所需的人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入
C language big job - Matching System