title: basic exercises Sine dance
categories:
- ACM
- Recursive
tags: - Logic
date: 2020-03-14 16:08:27
Careful observation, nested, then write it on the line
problem
Questions basic exercises Sine Dance
Resource constraints
Time limit: 1.0s Memory Limit: 512.0MB
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.
You may wish to set
An = SiN (. 1-SiN (2 + SiN (. 3-SiN (. 4 + ... SiN (n-)) ...)
of Sn = (... (A1 + n-) A2 + n--. 1) 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
algorithm
#include<iostream>
#include<string>
#include<stdio.h>
using namespace std;
void p(int s,int e)
{
if(s==e) {
printf("sin(%d)",e);
return ;
}
char c=s&1?'-':'+';
printf("sin(%d%c",s,c);
p(s+1,e);
cout<<")";
}
void pp(int an,int nn)
{
if(an==1)
{
p(1,an);
cout<<"+"<<nn;
return ;
}
cout<<"(";
pp(an-1,nn+1);
cout<<")";
p(1,an);
cout<<"+"<<nn;
}
int main(){
int n;
cin>>n;
pp(n,1);
}