zoukankan      html  css  js  c++  java
  • Spoj-BOKAM143SOU Checking cubes.

    Given a integer N. Find number of possible ways to represent N as a sum of at most five cubes.

    Input

    First line contains N.

    1<=N<=125000.

    Output

    Output the result

    Example

    Input:
    64
    
    Output:
    2

    这种题目。。直接暴力吧
     1 #include<cstdio>
     2 #include<iostream>
     3 #include<cstring>
     4 #include<cstdlib>
     5 #include<algorithm>
     6 #include<queue>
     7 #include<deque>
     8 #include<set>
     9 #include<map>
    10 #include<ctime>
    11 #define LL long long
    12 #define inf 0x7ffffff
    13 #define pa pair<int,int>
    14 #define pi 3.1415926535897932384626433832795028841971
    15 using namespace std;
    16 inline LL read()
    17 {
    18     LL x=0,f=1;char ch=getchar();
    19     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    20     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    21     return x*f;
    22 }
    23 inline void write(LL a)
    24 {
    25     if (a<0){printf("-");a=-a;}
    26     if (a>=10)write(a/10);
    27     putchar(a%10+'0');
    28 }
    29 inline void writeln(LL a){write(a);printf("
    ");}
    30 int n,m,tot,ans;
    31 int p[51];
    32 int mrk[125001];
    33 int main()
    34 {
    35     scanf("%d",&n);
    36     for (int i=1;i<=50;i++)p[i]=i*i*i,mrk[p[i]]=i;
    37     for (int i=0;i<=50;i++)
    38     {
    39         if (tot+p[i]>n)break;
    40         tot+=p[i];
    41         for (int j=i;j<=50;j++)
    42         {
    43             if(tot+p[j]>n)break;
    44             tot+=p[j];
    45             for (int k=j;k<=50;k++)
    46             {
    47                 if (tot+p[k]>n)break;
    48                 tot+=p[k];
    49                 for (int l=k;l<=50;l++)
    50                 {
    51                     if (tot+p[l]>n)break;
    52                     tot+=p[l];
    53                     for (int m=l;m<=50;m++)
    54                         if (tot+p[m]==n)ans++;
    55                     tot-=p[l];
    56                 }
    57                 tot-=p[k];
    58             }
    59             tot-=p[j];
    60         }
    61         tot-=p[i];
    62     }
    63     printf("%d
    ",ans);
    64 }
    Spoj BOKAM143SOU
    ——by zhber,转载请注明来源
  • 相关阅读:
    记账本微信小程序开发三
    记账本微信小程序开发二
    记账本微信小程序开发一
    一个Java系统测试
    河北省重大技术需求征集系统(5)
    河北省重大技术需求征集系统(4)
    河北省重大技术需求征集系统(3)
    河北省重大技术需求征集系统(2)
    《软件需求工程》阅读笔记02
    通过API操作HBase数据库
  • 原文地址:https://www.cnblogs.com/zhber/p/7153131.html
Copyright © 2011-2022 走看看