Table Decorations CodeForces - 478C

原题链接
考察:思维
过了这题的有1w+,本蒟蒻直接去死算了()
思路:
  假设排序后\(a[0],a[1],a[2]\)
  分两种情况:

  1. \(a[2]>=2(a[0]+a[1])\),此时答案为\(a[0]+a[1]\)
  2. \(a[2] < 2(a[0]+a[1])\),此时不断取a[2] 2个,a[1]取一个,直到\(a[2]\)不是最大的,此时必有:

\[max(a[1],a[0])-a[2]<=1 \]

\[max(a[1],a[0])-min(a[1],a[0])<=1 \]

  此时的最优解是(a[1]+a[2]+a[0])/3

Code

#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N =3;
LL a[N];
int main()
{
	for(int i=0;i<3;i++) scanf("%lld",&a[i]);
	sort(a,a+3);
	LL res = 0;
	if(a[2]>=2*(a[1]+a[0])) res = a[1]+a[0];
	else{
		int t = (a[2]-a[1]+1)/2;
		res+=t;
		a[2]-=t*2,a[1]-=t;
		res +=(a[1]+a[0]+a[2])/3;
	}
	printf("%lld\n",res);
	return 0;
}

posted @ 2021-06-30 22:56  acmloser  阅读(30)  评论(0编辑  收藏  举报