zoukankan      html  css  js  c++  java
  • 蓝桥---sine之舞(递归)

    Description

      最近FJ为他的奶牛们开设了数学分析课,FJ知道若要学好这门课,必须有一个好的三角函数基本功。所以他准备和奶牛们做一个“Sine之舞”的游戏,寓教于乐,提高奶牛们的计算能力。
    不妨设
    An=sin(1–sin(2+sin(3–sin(4+...sin(n))...)
    Sn=(...(A1+n)A2+n-1)A3+...+2)An+1
    FJ想让奶牛们计算Sn的值,请你帮助FJ打印出Sn的完整表达式,以方便奶牛们做题。

    Input

      仅有一个数:N<201。

    Output

      请输出相应的表达式Sn,以一个换行符结束。输出中不得含有多余的空格或换行、回车符。

    Sample Input

    3

    Sample Output

    ((sin(1)+3)sin(1–sin(2))+2)sin(1–sin(2+sin(3)))+1

    就一道简单递归,写两个递归函数AN,SN就行了

    不过改了一晚上,被这个减号坑惨了,"-"和"—"都不是题中的这个符号"–"

    无语。。。。。。。

    以后遇到符号一律复制,绝不手打

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 //const double PI=acos(-1);
    17 #define Bug cout<<"---------------------"<<endl
    18 const int maxm=1e6+10;
    19 const int maxn=1e5+10;
    20 using namespace std;
    21   
    22 void PTA(int t,int n)//输出AN
    23 {
    24     if(t>n)
    25         return ;
    26     printf("sin(%d",t);
    27     if(t!=n)
    28     {
    29         if(t%2)
    30             printf("");
    31         else
    32             printf("+");
    33     }
    34     PTA(t+1,n); 
    35     printf(")");
    36 }
    37   
    38 void PTS(int t,int n)//输出SN 
    39 {
    40     if(t<1)
    41         return ;
    42     if(t!=1)
    43         printf("(");
    44     PTS(t-1,n);
    45     if(t!=1)
    46         printf(")");
    47     PTA(1,t);
    48     printf("+%d",n+1-t);
    49 }
    50   
    51 int main()
    52 {
    53     int n;
    54     scanf("%d",&n);
    55     PTS(n,n);
    56     return 0;
    57 }

    差不多的:

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <string>
     5 #include <math.h>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <set>
    11 #include <map>
    12 #include <sstream>
    13 const int INF=0x3f3f3f3f;
    14 typedef long long LL;
    15 const int mod=1e9+7;
    16 //const double PI=acos(-1);
    17 #define Bug cout<<"---------------------"<<endl
    18 const int maxm=1e6+10;
    19 const int maxn=1e5+10;
    20 using namespace std;
    21  
    22 void PTA(int t,int n)
    23 {
    24     if(t==n)
    25     {
    26         printf("sin(%d)",t);
    27         return ;
    28     }   
    29     printf("sin(%d",t);
    30     if(t%2)
    31         printf("");
    32     else
    33         printf("+");
    34     PTA(t+1,n); 
    35     printf(")");
    36 }
    37  
    38 void PTS(int t,int n)
    39 {
    40     if(t==n)
    41     {
    42         PTA(1,1);
    43         printf("+%d",t);
    44         return ;
    45     }
    46     else
    47     {
    48         printf("(");
    49         PTS(t+1,n);
    50         printf(")");
    51         PTA(1,n-t+1);
    52         printf("+%d",t);
    53     }
    54 }
    55  
    56 int main()
    57 {
    58     int n;
    59     scanf("%d",&n);
    60     PTS(1,n);
    61     printf("
    ");
    62     return 0;
    63 }
  • 相关阅读:
    XAF-内置初始化数据 (XPO)
    XAF中多对多关系 (XPO)
    Implement Custom Business Classes and Reference Properties 实现自定义业务类和引用属性(XPO)
    Add a Class from the Business Class Library 从业务类库添加类 (XPO)
    Set a One-to-Many Relationship设置一对多关系 (XPO)
    Define the Data Model and Set the Initial Data 定义数据模型并设置初始数据
    Create an XAF Application 创建一个XAF应用程序
    XAF Architecture XAF架构
    功能区控件样式设置
    开源项目CIIP(企业信息管理系统框架).2018.1.0910版更新介绍-上周工作总结
  • 原文地址:https://www.cnblogs.com/jiamian/p/11780342.html
Copyright © 2011-2022 走看看