1. Title
Title link
http://lx.lanqiao.cn/problem.page?gpid=T62
Problem Description
Recently, FJ has set up a mathematical analysis course for his cows. FJ knows that to learn this course, he must have a good basic function of trigonometric functions. So he is going to make a "Sine Dance" game with the cows, to be entertaining and to improve the cows' computing power.
Let's set
An = sin (1–sin (2 + sin (3–sin (4 + ... sin (n)) ...)
Sn = (... (A1 + n) A2 + n-1) A3 + ... + 2) An + 1
FJ wants the cows to calculate the value of Sn. Please help FJ print out the complete expression of Sn, so that the cows can easily solve the problem.
Let's set
An = sin (1–sin (2 + sin (3–sin (4 + ... sin (n)) ...)
Sn = (... (A1 + n) A2 + n-1) A3 + ... + 2) An + 1
FJ wants the cows to calculate the value of Sn. Please help FJ print out the complete expression of Sn, so that the cows can easily solve the problem.
Input format
There is only one number: N <201.
Output format
Please output the corresponding expression Sn, ending with a newline character. The output must not contain extra spaces or line feeds or carriage returns.
Sample input
3
Sample output
((sin (1) +3) sin (1 – sin (2)) + 2) sin (1 – sin (2 + sin (3))) + 1
2. Solve
Idea: List the strings according to the two expressions given in the question
A[i]="A" + "sin(" + "i" + "i个)"
s is initially set to "n-1 '('"
s="s" + "A[i]" + "+" + "n-i+1" + "1个)"
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main(){ 4 int N; 5 char t; 6 cin>>N; 7 string s=""; 8 string A="",T="",H=""; 9 for(int i=0;i<N-1;i++){ 10 //s初始设为"n-1个'('" 11 s+='('; 12 } 13 14 for(int i=1;i<=N;i++){ 15 //A[i]="A" + "sin(" + "i" + "i个)" 16 T+=')';//T是')'的叠加体 17 A+="sin("; 18 t='0'+i; 19 A+=t;//A是A[i]的叠加体 20 H=A+T; //H表示A[i] 21 22 //s="s" + "H" + "+" + "n-i+1" + "1个)" 23 s+=H; 24 s+='+'; 25 t='0'+(N-i+1); 26 s+=t; 27 if(i!=N) s+=')'; 28 29 //Prepare for the next A [i] plus plus or minus sign 30 if (i% 2 == 1) A + = '-' ; 31 else A + = '+' ; 32 } 33 34 cout << s << endl; 35 }