JZOJ5872. 【NOIP2018提高组模拟9.18】小A的任务

在这里插入图片描述

题解

可以用柯西不等式来证明 ( 1 / s i + 1 / s j + 1 / s k ) ( s i 2 + s j 2 + s k 2 ) 3 ( s i + s j + s k ) (1/s_i+1/s_j+1/s_k)*(s_i^2+s_j^2+s_k^2)≥3*(s_i+s_j+s_k)
就是对左边拆出来的9项,配上(s_i+s_i+s_i+s_j+s_j+s_j+s_k+s_k+s_k)
那么答案就一定是全选,有特殊情况,全部相同的,就全部不选。
求答案就算一下系数。

code

#include <queue>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 10000003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
#define pi 3.1415926535897932384626433832795
using namespace std;
char ch;
void read(int &n)
{
	n=0;
	ch=G();
	while((ch<'0' || ch>'9') && ch!='-')ch=G();
	ll w=1;
	if(ch=='-')w=-1,ch=G();
	while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
	n*=w;
}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
void write(ll x){if(x>9) write(x/10);P(x%10+'0');}

const int mo=1000000007;
int n,s[N],ans,sum,w[1003][1003],S;
bool bz;

ll ksm(ll x,int y)
{
	ll s=1;
	for(;y;y>>=1,x=x*x%mo)
		if(y&1)s=s*x%mo;
	return s;
}

int main()
{	
	read(n);S=(ll)n*n%mo*3%mo;
	for(int i=1;i<=n;i++)
		read(s[i]),sum=(sum+(ll)s[i]*s[i])%mo;
	
	sum=(ll)sum*6*n%mo;
	
	for(int i=1;i<=n;i++)
		ans=(ans+ksm(s[i],mo-2)*sum%mo+(ll)s[i]*S%mo)%mo;
	
	bz=1;
	for(int i=2;i<=n;i++)
		if(s[i]^s[i-1])
		{
			bz=0;
			break;
		}
	
	printf("%d\n",ans);
	if(bz)P('0');else printf("%d\n",n);
	
	return 0;
}

猜你喜欢

转载自blog.csdn.net/lijf2001/article/details/82808090
今日推荐