UVa 10370 – Above Average


/*
User ID: turing_13
Link: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1311
*/

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,c,ara[1000],i,j=0;
    float ans,avarage=0;
    scanf("%d", &n);
    while(n--)
    {
        scanf("%d", &c);
        for(i=0;i<c;i++)
        {
            scanf("%d", &ara[i]);
            avarage+=(float)(ara[i]);
        }
        avarage/=c;
        for(i=0;i<c;i++)
        {
            if(ara[i]>avarage)
                j++;
        }
        ans=(float)j/c*100;
        printf("%.3lf%%\n",ans);
        avarage=j=0;
    }
    return 0;
}


Advertisements

Light OJ 1433 – Minimum Arc Distance

Problem Link : http://www.lightoj.com/volume_showproblem.php?problem=1433


#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define CIN ios_base::sync_with_stdio(0)
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define getint2(a,b) scanf("%d%d",&a,&b)
#define getint3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

/* Bits operation */
int Set(int n,int pos)  { return n = n | 1<<pos;}
bool check(int n,int pos) { return n & 1<<pos;}
int Reset(int n, int pos) { return n=n & ~(1<<pos);}

int main()
{
    ///freopen("in.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t,x,y;
    getint(t);

    TEST_CASE(t)
    {
        getint2(x,y);
        pii o(x,y);
        getint2(x,y);
        pii a(x,y);
        getint2(x,y);
        pii b(x,y);
        double ab=sqrt((a.ff-b.ff)*(a.ff-b.ff)+(a.ss-b.ss)*(a.ss-b.ss));
        double oa=sqrt((a.ff-o.ff)*(a.ff-o.ff)+(a.ss-o.ss)*(a.ss-o.ss));
        double ob=sqrt((b.ff-o.ff)*(b.ff-o.ff)+(b.ss-o.ss)*(b.ss-o.ss));
        double angle=acos(((oa*oa)+(ob*ob)-(ab*ab))/(2*oa*ob));
        PRINT_CASE;
        pf("%lf\n",angle*ob);
    }
    return 0;
}


Light OJ 1354 – IP Checking


/*
Link : http://www.lightoj.com/volume_showproblem.php?problem=1354
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define CIN ios_base::sync_with_stdio(0)
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

 string func(int a)
 {
     string str;
     while(a)
     {
         str+=(a%2)+'0';
         a/=2;
     }
     while(SZ(str)<8)
        str+='0';
     reverse(all(str));
     return str;
 }

int main()
{
    ///freopen("in.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t;
    cin>>t;
    TEST_CASE(t)
    {
        int a,b,c,d;
        sc("%d.%d.%d.%d",&a,&b,&c,&d);
        string str,temp[4];
        str.clear();
        loop(i,4)
            temp[i].clear();
        cin>>str;
        for(int i=0,cnt=0;i<SZ(str);i++)
        {
            if(str[i]=='.')
            {
                cnt++;
                continue;
            }
            temp[cnt]+=str[i];
        }

        PRINT_CASE;
        
        if(temp[0]!=func(a) || temp[1]!=func(b) || temp[2]!=func(c)|| temp[3]!=func(d))
        {
            cout<<"No"<<endl;
            continue;
        }
        else
            cout<<"Yes"<<endl;
    }
    return 0;
}

Light OJ : 1331 – Agent J


/*
Link : http://www.lightoj.com/volume_showproblem.php?problem=1331
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define CIN ios_base::sync_with_stdio(0)
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

double angle (double a, double b, double c)
{
    return acos((a*a+b*b-c*c)/(2*a*b));
}
int main()
{
    ///freopen("in.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    int t;
    cin>>t;
    TEST_CASE(t)
    {
        double r1,r2,r3;
        cin>>r1>>r2>>r3;
        double a,b,c;
        a=r1+r2;
        b=r3+r2;
        c=r3+r1;
        double s=(a+b+c)/2;
        double area = sqrt(s*(s-a)*(s-b)*(s-c));
        area-=angle(a,b,c)/2*r2*r2;
        area-=angle(a,c,b)/2*r1*r1;
        area-=angle(b,c,a)/2*r3*r3;
        PRINT_CASE;
        pf("%lf\n",area);
    }
    return 0;
}

Light OJ – 1311 – Unlucky Bird


/*
Link : http://www.lightoj.com/volume_showproblem.php?problem=1311
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define CIN ios_base::sync_with_stdio(0)
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

int main()
{
    ///freopen("in.txt","r",stdin);
    ///freopen("out.txt","w",stdout);

    int t;
    double v1,v2,v3,a1,a2,t1,t2;
    cin>>t;
    TEST_CASE(t)
    {
        cin>>v1>>v2>>v3>>a1>>a2;
        PRINT_CASE;
        t1=v1/a1;
        t2=v2/a2;
        double ans1=((v1*t1)-.5*a1*t1*t1)+((v2*t2)-.5*a2*t2*t2);
        double ans2=max(t1,t2)*v3;
        pf("%lf %lf\n",ans1,ans2);
    }
    return 0;
}


Light OJ 1249 – Chocolate Thief


/*
Link: http://www.lightoj.com/volume_showproblem.php?problem=1249
*/

#include <bits/stdc++.h>

#define pii pair <int,int>
#define sc scanf
#define pf printf
#define Pi 2*acos(0.0)
#define ms(a,b) memset(a, b, sizeof(a))
#define pb(a) push_back(a)
#define MP make_pair
#define oo 1<<29
#define dd double
#define ll long long
#define EPS 10E-10
#define ff first
#define ss second
#define MAX 10000
#define SZ(a) (int)a.size()
#define getint(a) scanf("%d",&a)
#define loop(i,n) for(int i=0;i<n;i++)
#define TEST_CASE(t) for(int z=1;z<=t;z++)
#define PRINT_CASE printf("Case %d: ",z)
#define all(a) a.begin(),a.end()
#define intlim 2147483648
#define inf 1000000
#define rtintlim 46340
#define llim 9223372036854775808
#define rtllim 3037000499
#define ull unsigned long long
#define I int

using namespace std;

/* Bits operation */
int Set(int n,int pos)  { return n = n | 1<<pos;}
bool check(int n,int pos) { return n & 1<<pos;}
int Reset(int n, int pos) { return n=n & ~(1<<pos);}

struct data
{
    string name;
    int cube=0;
};

bool test(data a, data b)
{
    return a.cube < b.cube;
}
int main()
{
    ///freopen("in.txt","r",stdin);
    ///freopen("out.txt","w",stdout);
    vector<data>v;
    int t,n;
    getint(t);
    TEST_CASE(t)
    {
        data temp;
        int a,b,c;
        getint(n);
        loop(i,n)
        {
            cin>>temp.name;
            getint(a);
            getint(b);
            getint(c);
            temp.cube=a*b*c;
            v.pb(temp);
        }
        sort(all(v),test);
        PRINT_CASE;
        if(v[0].cube==v[n-1].cube)
            pf("no thief\n");
        else
        {
            cout<<v[n-1].name<<" ";
            pf("took chocolate from ");
            cout<<v[0].name<<endl;
        }
        v.clear();
    }
    return 0;
}