HUST 1606 Naive
预处理一下,然后o(1)询问。
#include<cstdio> #include<cstring> #include<cmath> #include<string> #include<stack> #include<map> #include<algorithm> using namespace std; int x; int a[200]; map<int, bool>m; void init() { m.clear(); int tot = 0; for (int i = 1; i <= 100; i++) a[tot++] = i*i*i; for (int i = 0; i < tot; i++) { for (int j = 0; j < tot; j++) { for (int z = 0; z < tot; z++) { m[a[i] + a[j] + a[z]] = 1; } } } } int main() { init(); while (~scanf("%d", &x)) { if (m[x]) printf("Yes\n"); else printf("No\n"); } return 0; }