D. Domino for Young 题解(二分图染色)
题目链接
题目思路
这个有贪心的做法
但是看有大佬说对于这种多米诺骨牌问题,二分图染色最好
确实把这个图等价于二分图染色
求白点和黑点的最小值即为答案
代码
#include<bits/stdc++.h>
#define fi first
#define se second
#define debug cout<<"I AM HERE"<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<long long,long long >
//typedef pair<long long,long long > pii
const int maxn=1e5+5,inf=0x3f3f3f3f,mod=1e9+7;
const double eps=1e-6;
const ll INF=0x3f3f3f3f3f3f3f3f;
int n;
ll cnt[2];
signed main(){
scanf("%d",&n);
for(int i=1,x;i<=n;i++){
scanf("%d",&x);
cnt[i%2]+=x/2+x%2;
cnt[1-i%2]+=x/2;
}
printf("%lld\n",min(cnt[0],cnt[1]));
return 0;
}
不摆烂了,写题