#include<bits/stdc++.h>#definelllonglong#definepiipair<int,int>#defineIOSios::sync_with_stdio(false); cin.tie(0); cout.tie(0)#definexfirst#defineysecondusingnamespace std;intmain(){
IOS;
ll n;
cin >> n;
ll ans =0,pre =0;for(int i =1; i <= n; i++){
ll x;
cin >> x;//优先选择两个木棍与前面的进行匹配//
ll k =min(x/2,pre);
ans += k;
x -= k*2;
pre -= k;
ans += x/3;
pre += x %3;}
cout << ans << endl;}
原题描述题意:给你n种木棍,每种木棍的长度为2(i-1),之后会给出n个数表示长度为2(i-1)有多少根,对于每一根木棍我们只能用一次,我们需要求最多组成多少个三角形。解法:贪心,我们只需要选择当前长度相同的两个木棍,之后我们匹配比它长度小的进行匹配,之后我们在进行匹配当前长度的三个木棍,贪心策略。#include<bits/stdc++.h>#define ll long long #define pii pair<int,int>#define IOS ios::sy