Problem A Dull DongGua
撰写:Hacker_vision
题目大意:n个数1,2,3,4……,n;给你每个数的出现次数,判断是否存在这n个数构成的序列满足相邻元素两两互异。
题解: 组合数学中的插空,可以证明只要出现次数最多的那个元素能够剩下所有元素分隔开即可(构成的空能被插满)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <climits>
#include <map>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#define eps 1e-10
#define clr(k,v) memset(k,v,sizeof(k));
using namespace std;
typedef long long ll;
const int SZ = 1<<20;
const int maxn=2e6+10;
struct fastio{
char inbuf[SZ];char outbuf[SZ];fastio(){
//输入输出挂
setvbuf(stdin,inbuf,_IOFBF,SZ);
setvbuf(stdout,outbuf,_IOFBF,SZ);
}}io;
int a[maxn];
int main()
{
//freopen("input.txt","r",stdin);
int T;scanf("%d",&T);
while(T--){
int n;scanf("%d",&n);
ll sum=0;
for(int i=0;i<n;i++) {
scanf("%d",a+i);
sum+=a[i];
}
int maxx=*max_element(a,a+n);
if(sum-maxx>=maxx-1) puts(