传送门
题目描述
给出一个不规则的网格。共 n n n列,每列有 a i a_{i} ai个格子。现在要将 1 ∗ 2 1 * 2 1∗2的骨牌不重叠的覆盖在网格上,求最多能放的骨牌数量。
分析
这种问题首先想到二分图染色,但是这道题如果这么去做的话会t的很惨
如果当前这一列是偶数个的话,那么我们可以将
a
i
/
2
a_{i} / 2
ai/2处理成白色和黑色,那么如果是奇数个怎么处理呢
因为我们设置了左下角格子的颜色,所以如果是奇数的情况下,奇数列和偶数列的颜色必不相同,最后统计一下即可
每一个黑色需要跟一个白色进行配对,选最小的颜色数即可
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e6 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
ll cnt[2];
int n;
int main() {
read(n);
for(int i = 1;i <= n;i++){
ll x;
read(x);
cnt[0] += x / 2;
cnt[1] += x / 2;
cnt[i % 2] += x % 2;
}
dl(min(cnt[0],cnt[1]));
return 0;
}
/**
* ┏┓ ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃ ┃
* ┃ ━ ┃ ++ + + +
* ████━████+
* ◥██◤ ◥██◤ +
* ┃ ┻ ┃
* ┃ ┃ + +
* ┗━┓ ┏━┛
* ┃ ┃ + + + +Code is far away from
* ┃ ┃ + bug with the animal protecting
* ┃ ┗━━━┓ 神兽保佑,代码无bug
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛ + + + +
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛+ + + +
*/