yist

\(\cdot\)对计数一窍不通。

Link

同样的题,人家写20行就搞定,我写120行依然出问题。

Solution

分类。 可以分成\((a+b+c)+3d\)或者\((a+d)+(b+c)+2e\)

第一种情况,枚举\(c\),枚举\(d\),维护一个数组找\(a+b=d-c\)的方案数

第二种情况,有\(a<b<c<d,a<b=c<d,a=b<c=d,a=b=c=d\)四种。要分别处理,并且添加一个限制(比如限定当前选择的是最大的)确保不重复。

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <cstdio>
#include <string>
struct Istream {
Istream() {
#ifndef ONLINE_JUDGE
#ifdef DEBUG
freopen("input","r",stdin);
#else
std::string fileName(__FILE__),name=fileName.substr(0,fileName.find('.'));
freopen((name+".in").c_str(),"r",stdin);
freopen((name+".out").c_str(),"w",stdout);
#endif
#endif
}
template <class T>
Istream &operator >>(T &x) {
static char ch;static bool neg;
for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
x=neg?-x:x;
return *this;
}
}is;
struct Ostream {
template <class T>
Ostream &operator <<(T x) {
x<0 && (putchar('-'),x=-x);
static char stack[233];static int top;
for(top=0;x;stack[++top]=x%10+'0',x/=10);
for(top==0 && (stack[top=1]='0');top;putchar(stack[top--]));
return *this;
}
Ostream &operator <<(char ch) {
putchar(ch);
return *this;
}
}os;
#include <map>
#include <cstring>
#include <algorithm>
#define int64 long long
const int MAXN=5000+11,MAXA=2e7+11;
int64 C[MAXN][5];
struct AtFirst {
AtFirst() {
C[0][0]=1;
for(int i=1;i<MAXN;++i) {
C[i][0]=1;
for(int j=1;j<=std::min(4,i);++j) {
C[i][j]=C[i-1][j-1]+C[i-1][j];
}
}
}
}autoRun;
int main() {
int n;is>>n;
static int a[MAXN];
static int64 single[MAXA],sum2[MAXA];
for(int i=1;i<=n;++i) {
is>>a[i];
single[a[i]]++;
}
std::sort(a+1,a+1+n);
n=std::unique(a+1,a+1+n)-a-1;
int64 Ans=0;
//(a+b+c)+d
for(int i=1;i<=n;++i) {
//a<b<c a<b=c a=b<c a=b=c 没法这么分类.
for(int j=i+1;j<=n;++j) {
Ans+=C[single[a[j]]][3]*sum2[a[j]-a[i]]*single[a[i]]//;//C[single[a[j]]][2]..
+C[single[a[j]]][3]*(a[i]*2<a[j] && a[j]-a[i]*2<a[i]?single[a[j]-a[i]*2]:0)*C[single[a[i]]][2];
//!!!!!!!!!!!!!!
}
if(a[i]%3==0) {
Ans+=C[single[a[i]]][3]*C[single[a[i]/3]][3];
}
for(int j=1;j<=i-1;++j) {
sum2[a[i]+a[j]]+=single[a[i]]*single[a[j]];
}
sum2[a[i]<<1]+=C[single[a[i]]][2];
}
memset(sum2,0,sizeof(sum2));
//(a+d)+(b+c)+2e
for(int i=1;i<=n;++i) {
//1 2 2 3 4 4 !!!!!!!
for(int j=i+1;j<=n;++j) if(a[j]-a[i]<a[i]) {//>..
Ans+=C[single[a[j]]][2]*single[a[j]-a[i]]*single[a[i]]*(sum2[a[j]]+((a[j]&1)==0?C[single[a[j]>>1]][2]:0))
+C[single[a[j]]][2]*C[single[a[j]-a[i]]][2]*C[single[a[i]]][2];
}
//a=b<c=d
//sum2全都是instinct的
//a==b==c==d
Ans+=C[single[a[i]]][4]*C[single[a[i]<<1]][2];
for(int j=1;j<=i-1;++j) {
sum2[a[i]+a[j]]+=single[a[i]]*single[a[j]];
}
}
os<<Ans<<'\n';
return 0;
}

Powered by Hexo and Hexo-theme-hiker

Copyright © 2013 - 2017 Hey,Lucida here. All Rights Reserved.

Lucida Lu 保留所有权利