Domino for Young
参考:
Codeforces Round #609 (DIV 2) D. Domino for Young
题解的想法是将图形进行黑白交替染色
类似于:
01
101
0101
10101
010101
黑白中个数最少的那个即是答案:
// Created by CAD on 2020/2/13.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
ll ans1=0,ans2=0;
for(int i=1;i<=n;++i){
int x; cin>>x;
ans1+=x/2,ans2+=x/2;
if(x&1){
if(i&1) ans1++;
else ans2++;
}
}
cout<<min(ans1,ans2)<<endl;
return 0;
}
n=int(input())
a=list(map(int,input().split()))
ans1=ans2=0
for i in range(n):
ans1+=a[i]//2;ans2+=a[i]//2;
if a[i]%2==1:
if i&1==1:
ans1+=1
else:
ans2+=1
print(min(ans1,ans2))
CAD加油!欢迎跟我一起讨论学习算法,QQ:1401650042