首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2013-10-10 
(贪心5.1.2)POJ 2287 Tian Ji -- The Horse Racing/* * POJ_2287.cpp * *Created on: 2013年10月9日 *Auth

(贪心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;}

热点排行