Africa and the Middle East – Africa and Arab – 2010/2011   Leave a comment


4964 – What’s Next?

import java.util.Scanner;

public class WhatsNext {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a, b, c;
		a = in.nextInt();
		b = in.nextInt();
		c = in.nextInt();
		while (a != 0 || b != 0 || c != 0) {
			if (c - b == b - a)
				System.out.println("AP " + (c + b - a));
			else
				System.out.println("GP " + (c * (b / a)));
			a = in.nextInt();
			b = in.nextInt();
			c = in.nextInt();
		}
	}
}

4967 – Tri graphs

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class TriGraphs {

	public static void main(String[] args) throws IOException {
		BufferedReader buf = new BufferedReader(
				new InputStreamReader(System.in));
		int count = 1;

		while (true) {
			int m = Integer.parseInt(buf.readLine().trim());
			if (m == 0)
				break;
			int n = m * 3;
			int j = 0;
			long[] costs = new long[n];
			for (int i = 0; i < m; i++) {
				String input = buf.readLine().trim();
				String[] line = input.split(" ");
				costs[j++] = Long.parseLong(line[0]);
				costs[j++] = Long.parseLong(line[1]);
				costs[j++] = Long.parseLong(line[2]);
			}
			costs[n - 1] = Integer.MAX_VALUE;
			costs[n - 3] += costs[n - 2];
			for (int i = n - 4; i >= 0; i--) {
				if (i % 3 == 0)
					costs[i] += Math.min(costs[i + 1], Math.min(costs[i + 3],
							costs[i + 4]));
				if (i % 3 == 1) {
					costs[i] += Math.min(Math.min(costs[i + 1], costs[i + 2]),
							Math.min(costs[i + 3], costs[i + 4]));
				}
				if (i % 3 == 2) {
					costs[i] += Math.min(costs[i + 2], costs[i + 3]);
				}
			}
			System.out.println((count++) + ". " + costs[1]);
		}
	}
}

I will update this when we get more AC

Advertisements

Posted September 4, 2011 by epicrado in ACM-ICPC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: