//poj 2636 居然一次AC,好开心,题目要求在一个电源的情况下如何放排插才可
以有最多的孔给电器用
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
int main()
{
int n;
cin>>n;
int t;
int a[20];
for(int i = 0; i < n; i++)
{
memset(a, 0, sizeof(a));
cin>>t;
for(int j = 0; j < t; j++)
{
cin>>a[j];
}
sort(a, a + t);
int num = 0;
if(a[t-1] >= t)
{
for(int j = 0; j < t - 1; j++)
num += a[j];
num += a[t-1] - t + 1;
}
else
{
for(int j = 0; j < a[t-1] - 1; j++)
{
num += a[t-2-j];
}
for(int j = a[t-1] + 1; j < t; j++)
num += a[t-j] - 1;
num += a[0];
}
cout<<num<<endl;
}
return 0;
}
poj 2636
最新推荐文章于 2016-01-30 21:12:00 发布