zoukankan      html  css  js  c++  java
  • JS Set

    题目描述

    Let’s consider some math problems. 
    JSZKC has a set A={1,2,…,N}. He defines a subset of A as ‘Meo set’ if there doesn’t exist two integers in this subset with difference one. For example, When A={1,2,3}, {1},{2},{3},{1,3} are ‘Meo set’. 
    For each ‘Meo set’, we can calculate the product of all the integers in it. And then we square this product. At last, we can sum up all the square result of the ‘Meo set’. 
    So please output the final result. 

    输入

    The input file contains several test cases, each of them as described below. 
    • The first line of the input contains one integers N (1 ≤ N≤ 100), giving the size of the set.   
    There are no more than 100 test cases. 

    输出

    One line per case, an integer indicates the answer

    样例输入

    3
    

    样例输出

    23
    
    这个丢给有道翻译怎么看也看不懂....
    主要是这句calculate the product of all the integers 就是将子序列中乘起来
    然后找规律发现是(n+1)!-1
    涉及到高精度 不会Java
    #include <bits/stdc++.h>
    using namespace std;
    const int MAXN=10000;
    int f[MAXN];
    int main()
    {
        int i,j,n;
        while(scanf("%d",&n)!=EOF)
        {
            memset(f,0,sizeof(f));
            f[0]=1;
            for(i=2;i<=n+1;i++)
            {
                int c=0;
                for(j=0;j<MAXN;j++)
                {
                    int s=f[j]*i+c;
                    f[j]=s%10;
                    c=s/10;
                }
            }
            f[0]-=1;
            j=0;
            while(f[j]<0){
                f[j]+=10;
                j++;
                f[j]-=1;
            }
            for(j=MAXN-1;j>=0;j--)
               if(f[j]) break;//忽略前导0
            for(i=j;i>=0;i--){
                    printf("%d",f[i]);
            }
            printf("
    ");
        }
        return 0;
    }
    View Code


    不要忘记努力,不要辜负自己 欢迎指正 QQ:1468580561
  • 相关阅读:
    第二阶段团队项目冲刺第三天
    第二阶段团队项目冲刺第二天
    第二阶段团队项目冲刺第一天
    第二次冲刺站立会议05
    第二次冲刺站立会议04
    第二次冲刺站立会议03
    第二次冲刺站立会议02
    第二次冲刺站立会议01
    第二次冲刺计划会议
    cnblogs.com的用户体验
  • 原文地址:https://www.cnblogs.com/smallocean/p/9141577.html
Copyright © 2011-2022 走看看