http://poj.org/problem?id=1840
問題の意味:シーク\(a_1x_1 ^ 3 + a_2x_2 ^ 3 + a_3x_3 ^ 3 + a_4x_4 ^ 3 + a_5x_5 ^ = 0 3 \) すべての変数の値は整数解、\([ - 50,50] \ )、および\(X_I \ NEQ 0 \)
暴力の列挙が、どのように2年半、それに?事実は、2ポイントの前半は、3点の後半は良くなることを証明した、となぜか?
それはおそらくもっとある\(\ LOG_ {2}、{ 100} \) 、それはほぼ7倍で一定です。
両者の前半である:
\(O(N-2 ^ \ログ(N-2 ^)+ N- ^ 3 \ログ(N-2 ^))\)。
それは面白いですよりも、無駄定数の3〜7倍以上の前半、。
残念ながらPOJは、unordered_mapを取るハッシュ手書きの外観外となりますか?
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
map<int, int> M;
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
int a1, a2, a3, a4, a5;
scanf("%d%d%d%d%d", &a1, &a2, &a3, &a4, &a5);
for(int x1 = -50; x1 <= 50; ++x1) {
if(x1 == 0)
continue;
int p1 = a1 * x1 * x1 * x1;
for(int x2 = -50; x2 <= 50; ++x2) {
if(x2 == 0)
continue;
int p2 = a2 * x2 * x2 * x2;
M[p1 + p2]++;
}
}
ll ans = 0;
for(int x3 = -50; x3 <= 50; ++x3) {
if(x3 == 0)
continue;
int p3 = a3 * x3 * x3 * x3;
for(int x4 = -50; x4 <= 50; ++x4) {
if(x4 == 0)
continue;
int p4 = a4 * x4 * x4 * x4;
for(int x5 = -50; x5 <= 50; ++x5) {
if(x5 == 0)
continue;
int p5 = a5 * x5 * x5 * x5;
map<int, int>::iterator it = M.find(-p3 - p4 - p5);
if(it != M.end())
ans += it->second;
}
}
}
printf("%lld\n", ans);
}