Showing posts with label 2015-2016 ACM ICPC Baltic Selection Contest Solution. Show all posts
Showing posts with label 2015-2016 ACM ICPC Baltic Selection Contest Solution. Show all posts

Wednesday, 28 October 2015

Codeforces Gym 100796I - Shell Game Problem_Soultion

/*
Tanzila Islam
Southeast University
mail : tanzilamohita@gmail.com
Problem Link : http://codeforces.com/gym/100796/problem/I
*/
#include<bits/stdc++.h>
using namespace std;

int main () {
    double h, R, r;
    cin >> r >> R >> h;

    double H = h +(h*r)/(R-r);
    double c = sqrt(H*H+R*R);
    R=R+R;
    double a = 0.5*H*R;
    double s = (R+c+c)*0.5;
    double ans = 2*(a/s);
    ans = min(ans, h);

    printf ("%0.12lf", ans*0.5);
    return 0;
}

Codeforces Gym 100796G - Robot Walk Problem_Solution

/*
Tanzila Islam
Southeast University
mail : tanzilamohita@gmail.com
Problem Link : http://codeforces.com/gym/100796/problem/G
*/
#include<string>
#include<iostream>
using namespace std;

int main () {
    int n,x,m;
    string s1, s2;
    cin >> n >> x >> s1 >> m >> s2;
    x--;
    cout << s1[x];
    for (int i = 0; i < m; i++){
        if (s2[i] == 'R'){
            cout << s1[x+1];
            x++;
        }
        else if (s2[i] == 'L'){
            cout << s1[x-1];
            x--;
        }
    }
    cout << endl;
return 0;
}

Codeforces Gym 100796L - Emoticons Problem_Solution

/*
Tanzila Islam
Southeast University
mail : tanzilamohita@gmail.com
Problem Link : http://codeforces.com/gym/100796/problem/L
*/
#include<string>
#include<iostream>
using namespace std;

int main () {
    int n, l, sc, fc;
    string s;
    while (cin >> n) {
        cin >> s;
        l = s.length();
        sc = 0;
        fc = 0;
        if (n==1){
           cout << "BORED" << endl;
        }
        else {
            for (int i = 0; i < n-1; i++) {
                 if(s[i] == ':') {
                    if(s[i+1] == ')'){
                        sc++;
                       }
               else if (s[i+1] == '('){
                   fc++;
                 }
              }
           else if (s[i] == ')'){
                if (s[i+1] == ':'){
                     fc++;
               }
              }
              else if (s[i] == '('){
                if (s[i+1] == ':'){
                     sc++;
               }
              }
            }
if (fc > sc){
    cout << "SAD" << endl;
}
else if (sc > fc) {
      cout << "HAPPY" << endl;
}
else {
     cout << "BORED" << endl;
}
}
}
return 0;
}

Codeforces Gym 100796H - Game of Corners Problem_Solution

/*
Tanzila Islam
Southeast University
mail : tanzilamohita@gmail.com
Problem Link : http://codeforces.com/gym/100796/problem/H
*/
#include<iostream>
using namespace std;

int main(){
  long long int n,m;
  while(cin >> n >> m){
    if(n>m)
      cout << m*(n+1) << endl;
else  
      cout << n*(m+1) << endl;
}
return 0;
}

Another Solution :
#include<iostream>
using namespace std;
int main(){
long long m, n;
cin >> n >> m;
if(m < n){
    long long s = n;
    n = m;
    m = s;
}
long long ans = 0;
ans = n * (m+1);

cout << ans << endl;
return 0;
}

Friday, 23 October 2015

Codeforces Gym 100796F - Unusual Sum Problem_Solution

/*
Tanzila Islam
Southeast University
mail : tanzilamohita@gmail.com
Problem Link : http://codeforces.com/gym/100796/problem/F
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int main(){
int t;
double l, r;
scanf("%d", &t);
while(t--){
scanf("%lf%lf", &l, &r);
printf("%.12lf\n", (1/l)-(1/(r+1)));
}
return 0;
}

Codeforces Gym 100796A - AHB Problem_Solution

/*
Tanzila Islam
Southeast University
mail : tanzilamohita@gmail.com
Problem Link : http://codeforces.com/gym/100796/problem/A
*/
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>

using namespace std;

int main() {
    string a, b;
    long long int ans[100];
    while(cin >> a >> b){
        if(a.size() != b.size())
            break;
        else if(a==b) cout << "0" << endl;

        bool flag = false;
        for(int i=0; i<a.size(); i++) {
            ans[i]=abs((a[i]-48)-(b[i]-48));
            if (ans[i] > 0) flag = true;
            if (flag) cout << ans[i];
        }
        cout << endl;
    }
    return 0;
}