题解:P9941 [USACO21JAN] Even More Odd Photos B
P9941题解
题目传送门
看到题解区里没有和我一样的做法,就来写这篇题解了。
前置芝士
众所周知:
奇数+奇数=偶数
奇数+偶数=奇数
偶数+偶数=偶数
题意分析
有
解题思路
我们设
代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 1e3 + 5;
ll n, a[N], js, os;
bool check(ll x){
ll ans = os * 2 + js - (ll)ceil(x / 2.0) * 2 - x / 2;
return ans >= 0 && ans % 2 == 0 && js >= x / 2;//思路同上
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
for(int i = 1; i <= n; i++){//统计奇数和偶数
if(!(a[i] % 2)){
os++;
}else{
js++;
}
}
for(int i = n; i >= 1; i--){
if(check(i)){//判断分成i组是否可以
cout << i;
break;
}
}
return 0;
}