就是给你N个木棍,问他们能拼成多少个三角形
就从小到大排序,然后贪心地取就行
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
using namespace std;
#define ll long long
ll num[20];
bool used[20];
int main()
{
//freopen("input.txt", "r", stdin);
int N;
scanf("%d", &N);
for (int i = 0; i < N; ++i)
scanf("%I64d", &num[i]);
sort(num, num + N);
int ans = 0;
for (int i = 0; i < N; ++i)
{
if (used[i])
continue;
for (int j = i + 1; j < N; ++j)
{
if (used[j])
continue;
if (used[i])
break;
for (int k = j + 1; k < N; ++k)
{
if (used[k])
continue;
if (used[j])
break;
if (used[i])
break;
if (num[i] + num[j]>num[k])
{
//printf("%d %d %d\n", i, j, k);
used[i] = true; used[j] = true; used[k] = true;
++ans;
}
}
}
}
printf("%d\n", ans);
//while (1);
return 0;
}