Showing posts with label uva. Show all posts
Showing posts with label uva. Show all posts

10424 Love Calculator

10424 Love Calculator

10424 Love Calculator

#include<bits/stdc++.h>
using namespace std;


int main()
{

    string a,b;
    while(getline(cin,a))
    {

        getline(cin,b);
        float rat;
        long s1=0,s2=0;
        for(int i=0;i<a.length();i++)
        {
            char t=tolower(a[i]);
            //cout<<t;

            if(t>='a'&&t<='z')
            {
                s1+=t-'a'+1;

            }



        }
        if(s1%9==0) s1=9;
        else s1%=9;

        for(int i=0;i<b.length();i++)
        {
            char t=tolower(b[i]);
            //cout<<t;

            if(t>='a'&&t<='z')
            {
                s2+=t-'a'+1;

            }



        }
        if(s2%9==0) s2=9;
        else s2%=9;


        if(s1>s2)
            rat=((float)s2/s1)*100.0;
        else
            rat=((float)s1/s2)*100;
        printf("%.2lf %c\n",rat,'%');


    }



    return 0;
}

DFS BFS problem list UVA

DFS BFS problem list UVA
problem list UVA

************ DFS ***********************
* 00112 Tree Summing * 
* 00140 Bandwidth * 
* 00155 All Squares * 
* 00165 Stamps * 
* 00193 Graph Colouring * 
* 00195 Anagrams * 
* 00208 Firetruck * 
* 00216 Getting in Line * 
* 00280 Vertex * 
* 00296 Safebreaker * 
* 00301 Transportation * 
* 00380 Call forwarding * 
* 00385 Slurpys * 
* 00399 Another Puzzling Problem * 
* 00416 LED test * 
* 00441 Lotto * 
* 00469 Wetlands of florida * 
* 00529 Addition chains * 
* 00539 Settlers of Catan * 
* 00565 Pizza Anyone? * 
* 00571 Jugs (bfs appr) * 
* 00574 Sum It Up * 
* 00590 Always on the run *
* 00598 Bundling Newspapers *
* 00610 Street Directions *
* 00620 Cellular Structure * 
* 00657 The die is cast * 
* 00677 All Walks of * 
* 00628 Passwords * 
* 00639 Don't Get Rooked * 
* 00656 Optimal Programs * 
* 00729 Hamming Distance Problem *
* 00732 Anagrams by Stack * 
* 00743 The MTM Machine * 
* 00776 Monkeys in a Regular Forest *
* 00782 Contour Painting *
* 00784 Maze Exploration * 
* 00785 Grid Colouring * 
* 10004 Bicoloring * 
* 10063 Knuth's Permutation * 
* 10068 Treasure Hunt, the * 
* 10098 Generating FastSorted Permutations *
* 10186 Euro Cup 2000 * 
* 10276 Hanoi Tower Troubles Again! *
* 10285 Longest Run on a Snowboard * 
* 10344 23 out of 5 *
* 10364 Square * 
* 10400 Game Show Math * 
* 10419 Sum-up the Primes * 
* 10422 Knights in FEN * 
* 10447 Sum-up the Primes II * 
* 10496 Collecting Beepers * 
* 10501 Simplified Shisen-Sho * 
* 10503 Domino Solitaire, the * 
* 10513 Bangladesh Sequences * 
* 10582 ASCII Labyrinth *
* 10605 Mines for Diamonds * 
* 10637 Coprimes *
*********************************************

************* BFS ******************
* 00321 The new Villa *
* 00336 Node too far * 
* 00383 Shipping routes *
* 00429 word transformation * 
* 00567 Risk * 
* 00589 Pushing boxes *
* 00633 Chess knight *
* 00642 Word Amalgamation * 
* 00707 Robbery *
* 00762 We Ship Cheap *
* 10009 All Roads Lead Where? *
* 10422 Knights in FEN * 
**************************************

11057 - Exact Sum

11057 - Exact Sum
11057 - Exact Sum


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        vector<int>v;
        for(int i=0;i<n;i++)
        {
            int y;
            cin>>y;
            v.push_back(y);
        }
        int m;
        cin>>m;
        int b1,b2;
        sort(v.begin(),v.end());
        for(int i=0;i<v.size()-1;i++)
        {
            for(int j=i+1;j<v.size();j++)
            {
                if(v[i]+v[j]==m)
                {
                    b1=v[i];
                    b2=v[j];
                }
            }

        }
        printf("Peter should buy books whose prices are %d and %d.\n\n", b1, b2);


    }


    return 0;
}

10954 - Add All

10954 - Add All
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    int x;
    while(1)
    {
        scanf("%d",&n);
        if(n==0) break;
        priority_queue<int, vector<int>, greater<int> >v;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            v.push(x);

        }


        int t;
        int sum=0;
        while(v.size()>=2)
        {
            t=v.top();
            v.pop();
            t+=v.top();
            v.pop();


            sum+=t;
            v.push(t);
        }
        cout<<sum<<endl;

    }

    return 0;
}

10019 - Funny Encryption Method

10019 - Funny Encryption Method
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
    for(int t=1;t<=n;t++)
    {
        int bc=0,hc=0,h=0;
        cin>>m;
        int b=m;
        while(m!=0)
        {
            if((m&1)==1)
                bc++;
            m>>=1;
            //cout<<(m&1)<<endl;
        }

        h+=(b/10000)*pow(16,4);
        b%=10000;
        //cout<<h<<endl;

        h+=(b/1000)*pow(16,3);
        b%=1000;
        //cout<<h<<endl;

        h+=(b/100)*pow(16,2);
        b%=100;

       // cout<<h<<endl;
        h+=(b/10)*pow(16,1);
        b%=10;
        //cout<<h<<endl;
        h+=b;
        //cout<<h<<endl;

         while(h!=0)
         {
            if((h&1)==1)
                hc++;
            h>>=1;
            //cout<<(m&1)<<endl;
         }
        cout<<bc<<" "<<hc<<endl;
    }
    return 0;
}

10195 - The Knights Of The Round Table

 10195 - The Knights Of The Round Table



                              



10195 - The Knights Of The Round Table


#include<bits/stdc++.h>
using namespace std;
#define pi 3.141592653589793

int main()
{
    double a,b,c;
    while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF)
    {
        if(a+b+c==0)
            printf("The radius of the round table is: 0.000\n");

        else
        {
           double s,r;
           s=(a+b+c)/2;
           r=(s-a)*(s-b)*(s-c)/s;
           printf("The radius of the round table is: %.3lf\n",sqrt(r));

        }
    }
    return 0;
}

438 - The Circumference of the Circle

 438 - The Circumference of the Circle

                   

438 - The Circumference of the Circle






#include<bits/stdc++.h>
using namespace std;
#define pi 3.141592653589793
double dist(double x1,double y1,double x2,double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

int main()
{
    double x1,x2,x3,y1,y2,y3;
    while(scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF)
    {
        double a,b,c;
        a=dist(x1,y1,x2,y2);
        b=dist(x1,y1,x3,y3);
        c=dist(x3,y3,x2,y2);

        double r=(a*b*c)/sqrt((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c));
        //cout<<r<<endl;
        r=2*pi*r;

        printf("%.2lf\n",r);

    }

    return 0;
}

476 - Points in Figures: Rectangles

476 - Points in Figures: Rectangles

476 - Points in Figures: Rectangles



#include<bits/stdc++.h>
using namespace std;
struct recPoint{   
 double x1,y1,x2,y2;};
int main(){
    char c;
    recPoint r[11];
    int i=0;
    while(true) 
   {
        cin>>c;
        if(c=='*') break;
        if(c=='r')                                  cin>>r[i].x1>>r[i].y1>>r[i].x2>>r[i].y2;        
i++;

    }    
double a,b;   
 int w=1,v;   
 bool flag=false;    
while(true)    { 
       cin>>a>>b;        flag=false;        v=-1;
        if(a==9999.9&&b==9999.9) break;        for(int j=0;j<i;j++)        {
            if(r[j].x1<a&&r[j].x2>a&&r[j].y1>b&&r[j].y2<b)            {

                flag=true;
                printf("Point %d is contained in figure %d\n",w,j+1);

            }        }
        if(!flag)
            printf("Point %d is not contained in any figure\n",w);        w++;    }
return 0;}