SPOJ4580 ABCDEF(meet in the middle)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SPOJ4580 ABCDEF(meet in the middle)相关的知识,希望对你有一定的参考价值。
?????????problem space ble spoj href ace include ?????? fine
??????
Sol
??????abcdef??????????????????
??????meet in the middle??????????????????abc????????????def???
??????d = 0??????????????????(??????wa???????????????)
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int MAXN = 101, SS = 2e6 + 10;
map<LL, LL> mp;
int N;
LL a[MAXN], ans;
int a1[SS], c1, a2[SS], c2, cnt[SS];
int main() {
// ios::sync_with_stdio(false);
cin >> N;
for(int i = 1; i <= N; i++) cin >> a[i];
sort(a + 1, a + N + 1);
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
for(int k = 1; k <= N; k++)
a1[++c1] = a[i] * a[j] + a[k];
for(int i = 1; i <= N; i++)
for(int j = 1; j <= N; j++)
for(int k = 1; k <= N; k++)
if(a[i] != 0) a2[++c2] = a[i] * (a[j] + a[k]);
sort(a1 + 1, a1 + c1 + 1);
sort(a2 + 1, a2 + c2 + 1);
for(int i = 1, j = 1; i <= c2; i++) {
if(i != 1 && (a2[i] == a2[i - 1])) {cnt[i] = cnt[i - 1]; continue;}
while(a1[j] <= a2[i] && j <= c1) {
if(a1[j] == a2[i]) cnt[i]++;
j++;
}
}
for(int i = 1; i <= c2; i++) ans += cnt[i];
cout << ans;
return 0;
}
以上是关于SPOJ4580 ABCDEF(meet in the middle)的主要内容,如果未能解决你的问题,请参考以下文章
gym102222KVertex Covers(高维前缀和,meet in the middle)
SPOJ - PGCD Primes in GCD Table(莫比乌斯反演)
spoj 1693 COCONUTS - Coconuts最小割
SPOJ220 Relevant Phrases of Annihilation