NBUT The Sum of F(x) and G(x)

时间:2014-05-10 09:57:54   收藏:0   阅读:300

题意:显而易见

思路:纯模拟,让下标确定为正数就是了

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int MAXN = 1000;

int n,m;
int arr[MAXN];
int vis[MAXN];

int main(){
	while (scanf("%d%d", &n, &m) != EOF){
		int c,p;
		memset(vis,0,sizeof(vis));
		for (int i = 0; i < n; i++){
			scanf("%d%d", &c, &p);
			arr[p+10] = c;
			vis[p+10] = 1;  //确保正数	
		}
		for (int i = 0; i < m; i++){
			scanf("%d%d", &c, &p);
			if (vis[p+10]){
				arr[p+10] += c;
				if (arr[p+10] == 0)
					vis[p+10] = 0;
			}
			else {
				vis[p+10] = 1;
				arr[p+10] = c;
			}
		}
		for (int i = 20; i >= 0; i--)
			if (vis[i])
				printf("%d %d\n", arr[i], i-10);
	}
	return 0;
}



NBUT The Sum of F(x) and G(x),布布扣,bubuko.com

评论(0)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!