(贪心5.1.2)POJ 2287 Tian Ji -- The Horse Racing

/*

 * POJ_2287.cpp

 *

 *  Created on: 2013年10月9日

 *      Author: Administrator

 */



#include <iostream>

#include <cstdio>

#include <algorithm>

#include <cmath>

using namespace std;



int main() {

	int n;

	int a[1010];

	int b[1010];

	while (scanf("%d", &n) != EOF, n) {

		int tl = 1, tr = n;

		int ql = 1, qr = n;

		int sum = 0;



		int i;

		for (i = 1; i <= n; ++i) {

			scanf("%d", &a[i]);

		}



		for (i = 1; i <= n; ++i) {

			scanf("%d", &b[i]);

		}



		sort(a + 1, a + 1 + n);

		sort(b + 1, b + 1 + n);

		while (tl <= tr) {

			if (a[tl] < b[ql]) {

				sum -= 200;



				tl++;

				qr--;

			} else if (a[tl] == b[ql]) {

				while (tl <= tr && ql <= qr) {

					if (a[tr] > b[qr]) {

						sum += 200;



						tr--;

						qr--;

					} else {

						if (a[tl] < b[qr]) {

							sum -= 200;

						}



						tl++;

						qr--;

						break;

					}

				}

			} else {

				sum += 200;



				tl++;

				ql++;

			}



		}

		printf("%d\n", sum);

	}



	return 0;

}


你可能感兴趣的:(poj)