Thursday, April 5, 2018

UVa problem 673 - Parentheses Balance

problem link:

Discuss: This problem i want to solve by counting parentheses before  i know stack. since i know i just laugh at myself. if you know stack then it is just implementation problem for you.there no tricky part in this problem

try yourself before see the code


UVa problem solution 727 - Equation

problem link:

Discuss: in this problem you may first trouble with taking input.it's quite okay it's a terrific one before but it's not like that. you can take input as string and if the first character of string is null character just break the loop.and obviously give a null end of your main string. and other simply need to convert it infix to post fix. if you know stack then it just  a implementation problem for you.

try your self, before see the code



Friday, March 9, 2018

UVa problem solution 10954 - Add All

problem link:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin >>n&&n)
    {
         int i,j,cnt=0,flag=0,a,b,x,sum=0;
        priority_queue<int>que;
        for(i=0;i<n;i++)
        {
            cin >>j;
            j*=-1;
            que.push(j);
        }
        while(que.size()!=1)
        {
            a=que.top();
            que.pop();
            b=que.top();
            que.pop();
            x=(a+b);
            sum+=(x*-1);
            que.push(x);
            if(que.size()==1)
                break;
        }

       cout <<sum<<endl;
    }
    return 0;
}

Wednesday, February 28, 2018

UVa problem solution 11503 - Virtual Friends

problem link:

Discuss: you can solve this problem by simply using disjoint set. just rank the set. and print for every new element. and there is no tricky part. you can use map for using  number instead of string.

try yourself, before see the code



UVa problem solution 10685 - Nature

problem link:

Discuss: you can simply solve this problem using disjoint set. just rank the set by counting the number of element in the set. and you can also use map for using number instead of string. and there is no tricky part in this problem.

try yourself before see the code



UVa problem 459 - Graph Connectivity


problem link:

Discuss: you can solve this problem in many ways like dfs,bfs, disjoint set. i used here disjoint set.just simply put the array element in vector and then erase every duplicate element for in similar set only number exist in vector. the i just count the number of element in the vector. there is also a case where no connectivity among nodes. if use scanf for scan newline than on that case it will not give you any output. so where any problem if need to scan a line only than use getchar() instead of scanf. and there is no more tricky part in this problem.


try your self, before see the code



Saturday, February 24, 2018

UVa problem solution 10608 - Friends

problem link:

Discuss: this is simple disjoint set problem. to solve this problem just use a extra array to store how much element add in a set. for that in make in makeUnion function when you check is the parent to node equal or not.then if not equal then you set ara[x]=y similar way we just count the member of the set also.such m[y]+=m[x] and just print the biggest element of the m array.there is no tricky part in this problem