# EOJ Monthly 2018.7

## A.数三角形

$a(n) = ((n - 1)^2*n^2*(n + 1)^2)/6 - 2*Sum(Sum((n - k + 1)*(n - l + 1)*gcd(k - 1, l - 1), k, 2, n), l, 2, n)$.

## B.锐角三角形

LL n;

int main()
{
if (n<=2){puts("No");return 0;}
if (n%2==0)
{
puts("Yes");
puts("0 0");puts("0 2");
print(n/2);puts(" 1");
}
else
{
puts("Yes");
puts("0 1");puts("1 0");
print(n/2+1);putchar(' ');print(n/2+1);puts("");
}
return 0;
}


## D.数蝌蚪

int n;
LL m,a[300010];

LL calc(LL x)
{
LL res=0,k=x;
for (int i=1;i<=n;i++)
res+=abs(a[i]-k),k+=m;
return res;
}

int main()
{
for (int i=1;i<=n;i++)
int l=0,r=1000000,mid1,mid2,ans;LL x,y;
while (l<=r)
{
if (r-l<=10) break;
mid1=l+(r-l)/3;mid2=l+(r-l)/3*2;
x=calc(mid1),y=calc(mid2);
if (x<y) r=mid2;
else l=mid1;
}
LL res=calc(l);
for (int i=l+1;i<=r;i++)
res=min(res,calc(i));
print(res),puts("");
return 0;
}


## E.对称与科学美

map<int,LL> a;
map<LL,int> c;
int n;
LL b[300010];

int main()
{
srand(time(NULL));
int x;LL y;
for (int i=1;i<=n;i++)
{
if (a.count(x)) y=a[x];
else{y=1LL;for (int j=1;j<=10;j++) y=y*rand();a[x]=y;}
b[i]=b[i-1]^y;
}
for (int i=0;i<=n;i++) c[b[i]]++;
LL ans=0;
for (map<LL,int>::iterator it=c.begin();it!=c.end();it++)
ans+=1ll*(it->second)*(it->second-1)/2ll;
print(ans),puts("");
return 0;
}


posted @ 2018-07-12 15:04  Xiejiadong  阅读(...)  评论(...编辑  收藏
levels of contents