ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1149. Sinus Dances

Easiest way to solve this problem [C++ code with command].
Posted by Akash 25 Aug 2020 00:35
/***************************************************************************************************
                         Anzmaul Haque Akash
                    DIU, Daffodil International University
                    E-mail: anzamul15-2297@diu.edu.bd
 Youtube:https://www.youtube.com/channel/UCXvXHUkxyLYKeQkIg_RyMBw
******************************************************************************************************/
#include<bits/stdc++.h>

#define ln     (int)1e6
#define pi     acos(-1.0)
#define pb     push_back
#define pf     push_front 1
#define mp     make_pair
#define F      first
#define S      second
#define INF    1000000000000000000
#define LES    -1000000000000000000
#define intlim 2147483648
#define ll     long long
#define ull    unsigned long long
#define str    string
#define in     insert

#define all(akash)       akash.begin(),akash.end()
#define ms(arr)          memset(arr,0,sizeof(arr))
#define msbooltrue(arr)  memset(arr,true,sizeof(arr))
#define msboolfalse(arr) memset(arr,false,sizeof(arr))
#define msINF(arr)       memset(arr,INF,sizeof(arr))
#define case1(cs)        cout<<"Case "<<cs<<": "
#define case2(cs)        cout<<"Case "<<cs<<":\n"
#define lb               cout<<"\n";

#define vec vector
#define qu  queue
#define li  list
#define pq  priority_queue
#define em  empty

#define fori(i,a,b) for(int i=0;i<b;i++)
#define ford(i,a,b) for(int i=b-1;i>=0;i--)
#define forc(ch);   for(char ch:str)

#define sc1(a)         scanf("%lld",&a)
#define sc2(a,b)       scanf("%lld %lld",&a,&b)
#define sc3(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define sc4(a,b,c,d)   scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sc5(a,b,c,d,e) scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)

using namespace std;

void solve(ll n){

    ll temp_n=n;

    temp_n--;

    for(ll i=0; i<n-1; i++){
        cout<<"(";
    }
    cout<<"sin(1)+"<<n<<")"; //Segment 1.

    str s="sin(1-sin("; // if n>1 this one is using for the template.


    for(ll i=2;i<=n;i++){ //main loop.

        str temp;
        temp.clear();
        temp=s;


        for(ll x=2; x<i;x++){ //This one creat middle of Every part.

            if(x%2==0){ //' + ' for even ' - ' for odd.
                temp+=to_string(x);
                temp+="+sin(";
            }
            else{
                temp+=to_string(x);
                temp+="-sin(";
            }

        }

        temp+=to_string(i);

        for(ll y=1;y<=i;y++){ //for closing ' ) ' every equation.
            temp+=")";
        }

        cout<<temp; //print each segment.

        if(temp_n > 1){
            cout<<"+"<<temp_n<<")"; //Printing every segment last digit with out 1.
        }
        temp_n--;
    }

    cout<<"+1";lb//This one for end.
}

int main()
{
    ll n;
    sc1(n);

    if(n>1){
        solve(n); //solve function.
    }
    else if(n==1){
        cout<<"sin(1)+1";lb //for 1.
    }

    return 0;
}



















Re: Easiest way to solve this problem [C++ code with command].
Posted by Akash 25 Aug 2020 00:41
0
1
sin(1)+1
2
(sin(1)+2)sin(1-sin(2))+1
3
((sin(1)+3)sin(1-sin(2))+2)sin(1-sin(2+sin(3)))+1
4
(((sin(1)+4)sin(1-sin(2))+3)sin(1-sin(2+sin(3)))+2)sin(1-sin(2+sin(3-sin(4))))+1
5
((((sin(1)+5)sin(1-sin(2))+4)sin(1-sin(2+sin(3)))+3)sin(1-sin(2+sin(3-sin(4))))+2)sin(1-sin(2+sin(3-sin(4+sin(5)))))+1
6
(((((sin(1)+6)sin(1-sin(2))+5)sin(1-sin(2+sin(3)))+4)sin(1-sin(2+sin(3-sin(4))))+3)sin(1-sin(2+sin(3-sin(4+sin(5)))))+2)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6))))))+1
7
((((((sin(1)+7)sin(1-sin(2))+6)sin(1-sin(2+sin(3)))+5)sin(1-sin(2+sin(3-sin(4))))+4)sin(1-sin(2+sin(3-sin(4+sin(5)))))+3)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6))))))+2)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7)))))))+1
8
(((((((sin(1)+8)sin(1-sin(2))+7)sin(1-sin(2+sin(3)))+6)sin(1-sin(2+sin(3-sin(4))))+5)sin(1-sin(2+sin(3-sin(4+sin(5)))))+4)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6))))))+3)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7)))))))+2)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7-sin(8))))))))+1
9
((((((((sin(1)+9)sin(1-sin(2))+8)sin(1-sin(2+sin(3)))+7)sin(1-sin(2+sin(3-sin(4))))+6)sin(1-sin(2+sin(3-sin(4+sin(5)))))+5)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6))))))+4)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7)))))))+3)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7-sin(8))))))))+2)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7-sin(8+sin(9)))))))))+1
10
(((((((((sin(1)+10)sin(1-sin(2))+9)sin(1-sin(2+sin(3)))+8)sin(1-sin(2+sin(3-sin(4))))+7)sin(1-sin(2+sin(3-sin(4+sin(5)))))+6)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6))))))+5)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7)))))))+4)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7-sin(8))))))))+3)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7-sin(8+sin(9)))))))))+2)sin(1-sin(2+sin(3-sin(4+sin(5-sin(6+sin(7-sin(8+sin(9-sin(10))))))))))+1