Tuesday, October 25, 2011

SRM522

Level 1 Level 2 Level 3
Div 1 Level 1 Level 2 Level 3
Div 2 Level 1 Level 2 Level 3
SRM522

Tutorials:

I don't think this match worthies me 2+ hours working on that. The problems are kind of easy and too tricky. It's more like a game. Nothing really technical there.

Division One - Level Three:

Solution

Source Code:


Division One - Level Two:

Solution

Source Code:


Division One - Level One:

Solution

Source Code:


Sivision Two - Level Three:

Solution

Source Code:

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class CorrectMultiplicationTwo {
    public int getMinimum(int a, int b, int c) {
        int mmin = Integer.MAX_VALUE;
        for (int i = 1; i <= 3000000; i++) {
            for (int j = 1; i * j <= 3000000; j++) {
                mmin = Math.min(mmin, Math.abs(i - a) + Math.abs(j - b)
                        + Math.abs(c - i * j));
            }
        }
        return mmin;
    }
    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!


Division Two - Level Two:

Solution

Source Code:

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class RowAndManyCoins {
    public String getWinner(String cells) {
        if (cells.startsWith("A") || cells.endsWith("A"))
            return "Alice";
        return "Bob";
    }

    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!


Division Two - Level One:

Solution

Source Code:

import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.awt.geom.*;

public class PointErasingTwo {
    public int getMaximum(int[] y) {
        int mmax = 0;
        for (int i = 0; i < y.length - 1; i++) {
            for (int j = i + 1; j < y.length; j++) {
                int ymin = Math.min(y[i], y[j]);
                int ymax = Math.max(y[i], y[j]);
                int tmp = 0;
                for (int p = 0; p < y.length; p++) {
                    if (p > i && p < j && y[p] > ymin && y[p] < ymax)
                        tmp++;
                    mmax = Math.max(mmax, tmp);
                }
            }
        }
        return mmax;
    }

    // <%:testing-code%>
}
// Powered by [KawigiEdit] 2.0!

No comments :