Problem Description
FJ recently opened a mathematical analysis course for his cows, FJ know to learn this course, it must have a good basic trigonometric functions. So he was ready and cows do a "Sine Dance" game, entertaining, raise cows computing power.
May assume
An SiN = (. 1-SiN (SiN 2 + (. 3-SiN (SiN. 4 + ... (n-)) ...)
of Sn = (... (n-A1 +). 1-n-A2 +) A3 + 2 + ...) an + 1
FJ want cows to calculate the value of Sn, please FJ help you print out the full expression of Sn to facilitate cows do problems.
May assume
An SiN = (. 1-SiN (SiN 2 + (. 3-SiN (SiN. 4 + ... (n-)) ...)
of Sn = (... (n-A1 +). 1-n-A2 +) A3 + 2 + ...) an + 1
FJ want cows to calculate the value of Sn, please FJ help you print out the full expression of Sn to facilitate cows do problems.
Input Format
Only a few: N <201.
Output Format
Please output the corresponding expression Sn, with a newline character. Output must not contain extra space or line feed, carriage return.
Sample input
3
Sample Output
((Sin (1) +3) sin (1-sin (2)) + 2) sin (1-sin (2 + sin (3))) + 1
Ideas: first calculate An, An and substituting the Sn into the can. An recursive use to solve and Sn.
1 #include<iostream> 2 using namespace std; 3 4 class dance 5 { 6 public: 7 int get_n() 8 { 9 cin>>n; 10 return n; 11 } 12 13 void dance_an(int i,int n) 14 { 15 if(i==n) 16 { 17 cout<<"sin("; 18 cout<<n; 19 cout<<")"; 20 } 21 else 22 { 23 cout<<"sin("; 24 cout<<i; 25 if(i<n) 26 { 27 if (i % 2 == 1) 28 { 29 cout << "-"; 30 } 31 else 32 { 33 cout << "+"; 34 } 35 } 36 dance_an(i+1,n); 37 cout<<")"; 38 } 39 } 40 41 void dance_sn(int i,int n) 42 { 43 if(i==1) 44 { 45 dance_an(1,i); 46 cout<<"+"; 47 cout<<n; 48 } 49 else 50 { 51 cout<<"("; 52 dance_sn(i-1,n); 53 cout<<")"; 54 dance_an(1,i); 55 cout<<"+"; 56 cout<<n-i+1; 57 } 58 } 59 private: 60 int n; 61 }; 62 63 int main(void) 64 { 65 dance cow; 66 int n=cow.get_n(); 67 cow.dance_sn(n,n); 68 return 0; 69 }