D. Domino for Young--------思维/染色法(难)

You are given a Young diagram.
在这里插入图片描述

Given diagram is a histogram with n columns of lengths a1,a2,…,an (a1≥a2≥…≥an≥1).

Young diagram for a=[3,2,2,2,1].
Your goal is to find the largest number of non-overlapping dominos that you can draw inside of this histogram, a domino is a 1×2 or 2×1 rectangle.

Input
The first line of input contain one integer n (1≤n≤300000): the number of columns in the given histogram.

The next line of input contains n integers a1,a2,…,an (1≤ai≤300000,ai≥ai+1): the lengths of columns.

Output
Output one integer: the largest number of non-overlapping dominos that you can draw inside of the given Young diagram.

Example
inputCopy

5
3 2 2 2 1
outputCopy
4
Note
Some of the possible solutions for the example:

解析:基于涂色用黑白两色给图上色,相邻方格不同色。数量少的颜色一定可匹配完。取两者最小值



#include<bits/stdc++.h>
using namespace std;
const int N=1e6+1000;
typedef long long ll;
int c[N],n; 
ll b[N];
int main()
{
	cin>>n;
	for(ll i=0;i<n;i++)
	{
		cin>>c[i];
		b[i%2]+=c[i]/2+c[i]%2;
		b[(i+1)%2]+=c[i]/2;
	}
	cout<<min(b[0],b[1])<<endl;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值