当前位置:网站首页>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;
}边栏推荐
- European standard plug en50075 test items
- Building SQL statements in Excel
- 《网络是怎么样连接的》读书笔记 - WEB服务端请求和响应(五)
- Development and application of NFT chain Games: Six noteworthy NFT trends in 2022
- Classe d'outils commune de fichier, application liée au flux (enregistrement)
- taro3.*中使用 dva 入门级别的哦
- Paging SQL (rownum, row_number, deny_rank, rank)
- Business Intelligence BI and business management decision-making thinking No. 3: business quality analysis
- Houdini图文笔记:VAT(3.0)导入UE4/5的设置向导[官方文档翻译]
- three.js和高德地图结合引入obj格式模型-效果演示
猜你喜欢

智能聊天机器人的优势在哪里?资深独立站卖家告诉你!

2022年第一季度保险服务数字化跟踪分析

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

To prevent enterprise data leakage, use the fortress machine of network security products!

硬件开发笔记(八): 硬件开发基本流程,制作一个USB转RS232的模块(七):创建基础DIP元器件(晶振)封装并关联原理图元器件

ROS2机器人f1tenth之CLI工具基础

Paging SQL (rownum, row_number, deny_rank, rank)

PostgreSQL source code learning (24) -- transaction log ⑤ - log writing to wal buffer

墨天轮“高可用架构”干货文档分享(含Oracle、MySQL、PG资料124篇)

Imgutil image processing tool class, text extraction, image watermarking
随机推荐
微信公共号开发,发送消息回复文本
无意发现的【TiDB缓存表】,竟能解决读写热点问题
小程序判断数据为不为空
Summary of recent work
Leetcode-234-palindrome linked list
微信公告号自动回复使用图灵机器人实现智能回复
Classe d'outils commune de fichier, application liée au flux (enregistrement)
华为云AOM 2.0版本发布
如何用好数据科学?
京东联盟API - 万能转链接口 - 京品库接口 - 接口定制
【云原生】Nacos-TaskManager 任务管理的使用
Mysql database naming conventions PDF
2022年第一季度保险服务数字化跟踪分析
mysql XA 分布式事务
C語言大作業——匹配系統
It is expected to significantly improve the computational performance of integrated photonic circuits. The Tsinghua team proposed a diffraction pattern neural network framework
发明了杀毒软件之后,他选择做一个极品混混
About sql+nosql: newsql database
Business Intelligence BI and business management decision-making thinking No. 3: business quality analysis
What is the time complexity of the redis command?? (the actual question is about the underlying structure of redis)