Wednesday, April 27, 2016

Solution of UVA 11152 - Colourful Flowers

View the problem UVa-11152


#include<bits/stdc++.h>
#define pi acos(-1)
using namespace std;
int main()
{
    int a, b, c;
    while(scanf("%d%d%d", &a,&b,&c)!=EOF){
        double r, R, area_tri, area_cir, s, ans1, ans2, ans3;
        s=(a+b+c)/2.0;
        area_tri=sqrt(s*(s-a)*(s-b)*(s-c));
        R=(a*b*c)/(4*area_tri);
        area_cir=pi*R*R;
        ans1=area_cir-area_tri;
        r=area_tri/s;
        ans3=pi*r*r;
        ans2=area_tri-ans3;
        printf("%.4lf %.4lf %.4lf\n", ans1,ans2,ans3);
    }
    return 0;
}

Sunday, April 24, 2016

Solution of LightOJ 1202 - Bishops

View the problem LightOJ 1202 - Bishops

 
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n, i=1, a, b, c, d, x, y;
     scanf("%d", &n);
     while(n--){
        scanf("%d%d%d%d", &a, &b, &c, &d);
        printf("Case %d: ", i++);
        x=abs(a-c);
        y=abs(b-d);
        if(x%2==y%2){
            if(x==y) printf("1\n");
            else printf("2\n");
        }
        else printf("impossible\n");
    }
    return 0;
}

Wednesday, April 20, 2016

Solution of Uva 459 - Graph Connectivity

 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
#include<bits/stdc++.h>
using namespace std;
int p[100];
int prt(int z){
    if(p[z]==z) return z;
    else return p[z]=prt(p[z]);
}
int main()
{
    int i, t;
    scanf("%d\n", &t);
    while(t--){
        int x, m[50]={0}, mx=0, y, n, z;
        string s, a;
        set<int>ss;

        scanf("\n");
        getline(cin, a);
        n=(int)a[0]-64;

        for(i=1; i<=n; i++) p[i]=i;

        while(getline(cin, s)){
            if(s.size()==0) break;
            else{
                x=(int)s[0]-64;
                y=(int)s[1]-64;
                p[prt(y)]=prt(x);
            }
        }
        for(i=1; i<=n; i++) {
            p[i]=prt(i);
           ss.insert(p[i]);
        }
        cout<<ss.size()<<endl;
        if(t)cout<<endl;
    }
    return 0;
}