Search

Blog of AsEs

Try Try && Try is The Key of Success

Category

Uva

Uva 12032 – The Monkey and the Oiled Bamboo

Problem Name :  The Monkey and the Oiled Bamboo

Problem Link : See Problem :  Uva 12032

Let, the height of the rungs from the ground are 2, 8, 11, 16, 21 respectively
maximum distance is 6, k=6
Jumped 2 foot from the ground to the 1st rung (ground to 1). Since I jumped less than k feet, k remains 6. 

Jumped 6 feet for the next rung (2 to 8). Since I jumped equal k feet, k becomes 5. 
Jumped 3 foot for the 3rd rung (8 to 11). So, k remains 5. 
Jumped 5 feet for the 4th rung (11 to 16). This k becomes 4. 
Jumped 5 feet for the 5th rung (16 to 21). This time i need to jump 5 but k is 4, you can’t complete the process.
So, the Ans = 6+1=7

Solution  :

#include<bits/stdc++.h>
#define pb push_back
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define rev(s) std::reverse(s.begin(), s.end())
//#define up std::transform(s.begin(), s.end(), s.begin(), ::toupper);
///string sb=s.substr(1,3);

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define INF (1<<28)
#define mod 1000000007

#define PI acos(-1.0)

#define tbeg clock_t _t=clock();
#define tend cout << "\n\nTime: " << (double)(clock()-_t)/CLOCKS_PER_SEC;

//#define PI 2*acos(0.0)
//#define 2ndPI acos(-1.0)
#define lowest std::transform(s.begin(), s.end(), s.begin(), ::tolower);
#define n2s(n) stringstream ss; ss<<n; string Get=ss.str()
#define CC(x) cout<<(x)<<endl
#define srt sort(a,a+n)
#define rep(i,n) for(long long i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define pi 2*acos(0)

typedef long long LL;

using namespace std;

LL BigMod(LL B,LL P,LL M){ LL R=1; while(P>0)  {if(P&1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (LL)R;} //compute b^p%m

int main()
{
    //read;
    //write;
    LL t, n, x, a, N, tc = 0;
    scanf("%lld",&t);
    while(t--)
    {
        LL Ans = 0;
        scanf("%lld",&n);
        scanf("%lld",&a);
        Ans = a;
        LL A[100009], T = 1;
        A[T++] = a;
        A[0] = 0;
        n = n - 1;
        while(n--)
        {
            scanf("%lld",&N);
            A[T++] = N;
            LL ans = N - a;
            Ans = max(Ans,ans);
            a = N;
        }
        LL k = Ans, ANS = 0;
        rep(i,T-1)
        {
            if((A[i+1] - A[i])==k) k--;
            else if((A[i+1] - A[i])>k){Ans = Ans + 1; break;}
        }
        printf("Case %lld: %lld\n",++tc,Ans);
    }
    return 0;

}

Uva 12527 – Different Digits

Problem Name :  Different Digits

Problem Link : See Problem : Uva – 12527

Solution  :

#include<bits/stdc++.h>
#define pb push_back
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define rev(s) std::reverse(s.begin(), s.end())
//#define up std::transform(s.begin(), s.end(), s.begin(), ::toupper);
///string sb=s.substr(1,3);

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)

#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define max4(a,b,c,d) max(max(a,b),max(c,d))

#define INF (1<<28)
#define mod 1000000007

#define tbeg clock_t _t=clock();
#define tend cout << "\n\nTime: " << (double)(clock()-_t)/CLOCKS_PER_SEC;

#define PI 2*acos(0.0)
#define low std::transform(s.begin(), s.end(), s.begin(), ::tolower);
#define n2s(n) stringstream ss; ss<<n; string s=ss.str()
#define CC(x) cout<<(x)<<endl
#define srt sort(a,a+n)
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)

typedef long long LL;

using namespace std;

int main()
{
    LL n, m, f, c = 0;
    while(cin>>n>>m)
    {
        c = 0;
        for(int i=n; i<=m; i++)
        {
            n2s(i);
            LL l = s.size();
            f=1;
            for(int j=0; j<l; j++)
            {
                for(int k=0; k<l; k++)
                {
                    if(k!=j)
                    {
                        if(s[j]==s[k]) {f=0; break;}
                    }
                }
                if(f==0){break;}
            }
            if(f==1) {c++;}
        }
        cout<<c<<endl;
    }
    return 0;
}

Uva 10611 – The Playboy Chimp

Problem Name :  The Playboy Chimp

Problem Link : See Problem : Uva – 10611

Its a so much easier Binary Search related Problem…
You have to think 4 Scenario for solving this problem  it will be,
1 . N(height of Luchu)<=1st Lady.
2. N>=Last Lady.
3. You will find N between heights of the all chimps.
4. Or, Exact N is  missing in heights of the all chimps !!!

Solution  :

#include<bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)

typedef long long LL;

using namespace std;


int main()
{
    LL l, n, x, q, N, temp = -99999999999999999;
    vector<LL>a;
    cin>>n;
    rep(i,n){cin>>x; if(x!=temp){a.pb(x); temp = x;}}
    n = a.size();
    cin>>q;
    rep(i,q)
    {
        cin>>N;
        LL low = 0, mid = n/2, up = n - 1, f = 1;
        if(N<=a[low]){if(a[low]==N){cout<<"X "<<a[low+1]<<endl;} else{cout<<"X "<<a[low]<<endl;}}
        else if(N>=a[up]){if(a[up]==N){cout<<a[up-1]<<" X"<<endl;} else{cout<<a[up]<<" X"<<endl;}}
        else
        {
            while(f)
            {
                if(a[mid]==N){cout<<a[mid-1]<<" "<<a[mid+1]<<endl; f = 0; break ;}
                else if(N<a[mid]&&N>a[mid-1]){cout<<a[mid-1]<<" "<<a[mid]<<endl; f = 0; break ;}
                else if(N>a[mid]&&N<a[mid+1]){cout<<a[mid]<<" "<<a[mid+1]<<endl; f = 0; break ;}
                else if(N>a[mid]){ low = mid ; mid = (low + up)/2;}
                else if(N<a[mid]){ up = mid; mid = (low+up)/2;}
            }
        }
    }
    return 0;
}

Uva – 11364 – Parking

Problem Name :  Parking

Problem Link : See Problem : Uva – 11364

Solution  :

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a[100],t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int s=100000,m=0;
        for(int i=0;i<n;i++)
            cin>>a[i];
        for(int i=0;i<n;i++){
            if(a[i]<s)
            {
                s=a[i];
            }
        }
        for(int j=0;j<n;j++)
        {
            if(a[j]>m)
                m=a[j];
        }
        cout<<((m-s)*2)<<endl;
    }

    return 0;
}

Uva – 11498 – Division of Nlogonia

Problem Name :  Division of Nlogonia

Problem Link : See Problem : Uva – 11498

Solution  :

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int k,n,m,x,y;
    while(1){
    cin>>k;
    if(k==0) break;
    cin>>n>>m;
    while(k--)
    {
        cin>>x>>y;
    if(x==n||y==m)
        cout<<"divisa"<<endl;
    else if(x>n&&y>m)
        cout<<"NE"<<endl;
    else if(x<n&&y>m)
        cout<<"NO"<<endl;
    else if(x>n&&y<m)
        cout<<"SE"<<endl;
    else
        cout<<"SO"<<endl;
    }
    }
    return 0;
}

Uva – 12279 – Emoogle Balance

Problem Name :  Emoogle Balance

Problem Link : See Problem : Uva – 12279

Solution  :

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int a[10000];
    int n,b,i,t=0;
    while(1)
    {
        cin>>n;
        b=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        if(a[i]==0)
        {
            b++;
        }
        cout<<"Case "<<++t<<": "<<((n-b)-b)<<endl;
    }
    return 0;
}

Uva – 1124 – Celebrity jeopardy

Problem Name :  Celebrity jeopardy

Problem Link : See Problem : Uva – 1124

Solution  :

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    char a[100000];
    while(gets(a))
    {
        cout<<a<<endl;
    }
    return 0;
}

Uva – 12250 – Language Detection

Problem Name :  Language Detection

Problem Link : See Problem : Uva – 12250

Solution  :

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
    string s;
    int t=0;
    while(cin>>s)
    {
        if(s=="#")
            break;
        else if(s=="HELLO")
            cout<<"Case "<<++t<<": ENGLISH"<<endl;
            else if(s=="HOLA")
                cout<<"Case "<<++t<<": SPANISH"<<endl;
            else if(s=="HALLO")
                cout<<"Case "<<++t<<": GERMAN"<<endl;
            else if(s=="BONJOUR")
                cout<<"Case "<<++t<<": FRENCH"<<endl;
            else if(s=="CIAO")
                cout<<"Case "<<++t<<": ITALIAN"<<endl;
            else if(s=="ZDRAVSTVUJTE")
                cout<<"Case "<<++t<<": RUSSIAN"<<endl;
            else
                cout<<"Case "<<++t<<": UNKNOWN"<<endl;
    }
    return 0;
}

Uva – 12403 – Save Setu

Problem Name :  Save Setu

Problem Link : See Problem : Uva – 12403

Solution  :

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
    string s;
    int t,a,b=0;
    cin>>t;
    while(t--)
    {
        cin>>s;
        if(s=="donate")
        {
            cin>>a;
            b=b+a;
        }
        else if(s=="report")
            cout<<b<<endl;
    }
    return 0;
}

Create a free website or blog at WordPress.com.

Up ↑