华中科大校赛预赛1606 Naive

来源:互联网 发布:淘宝线下实体店加盟费 编辑:程序博客网 时间:2024/06/10 00:11

Naive

Time Limit: 3 Sec  Memory Limit: 128 MB
Submissions: 316  Solved: 36

Description

Give you a positive integer x, determine whether it is the sum of three positive cubic numbers.

Input

There’re several test cases. For each case:
Only one line containing an integer x (1≤x≤10^6)

Output

For each test case, print “Yes” if it is or “No” if it isn’t.
(See sample for more details)

Sample Input

1310

Sample Output

NoYesYes

HINT

Source

Problem Setter : Zhou Zhou

题意:  一个数是否可以表示成3个数的立方和   3个数可以为同一个数


思路 :

一开始直接暴力 先输入n  再去判断n是不是符合条件   结果超时了

后来换了个思维  先找出符合条件的  再看n在不在  小水题把


#include<stdio.h>#include<string.h>int a[105];bool flag[1000000+10];int main(){int i,j,k,n,mid;    for(i=1;i<=100;i++)a[i]=i*i*i;    memset(flag,0,sizeof(flag));    for(i=1;i<=100;i++)for(j=i;j<=100;j++)for(k=j;k<=100;k++){                  mid=a[i]+a[j]+a[k];if(mid<=1000000)     flag[mid]=1;}while(scanf("%d",&n)!=EOF){if(flag[n]) printf("Yes\n");else printf("No\n");}return 0;}





原创粉丝点击