A. Neko Finds Grapes-奇偶的性质及运用-Codeforces Round #554 (Div. 2)

Neko Finds Grapes

time limit per test 2 seconds
memory limit per test 256 megabytes

题目链接https://codeforces.com/problemset/problem/1152/A
在这里插入图片描述
在这里插入图片描述


emmm,题目大意:给你n给锁和m把钥匙,你能干些****,只有当锁和钥匙数字之和为奇数是。。。问你他最多能干多少****

首先想到暴力:a对b找,b再对a找,然后相加。。。铁T

然后简化,和为奇数,则必然为一奇一偶,所以我们直接统计各个数列的奇数和偶数的个数就行了。。。

以下是AC代码:

#include <bits/stdc++.h>
using namespace std;
const int mac=1e5+10;
int a[mac],b[mac];
int main(){
	int n,m;
	cin>>n>>m;
	int odd1=0,odd2=0;
	for (int i=1; i<=n; i++){
		scanf ("%d",&a[i]);
		if (a[i]&1) odd1++;
	}
	for (int i=1; i<=m; i++){
		scanf ("%d",&b[i]);
		if (b[i]&1) odd2++;
	}
	int ans=0;
	if (odd1>=m-odd2) ans+=m-odd2;
	else ans+=odd1;
	if (odd2>n-odd1) ans+=n-odd1;
	else ans+=odd2;
	cout<<ans<<endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值