Codeforces 390A Inna and Alarm Clock(水题)

题目链接:Codeforces 390A Inna and Alarm Clock


题目大意:给出一些点,表示该点上有灯,每次可以关掉一排或者一竖的灯,问说最少需要关几次。


解题思路:水题,计算出横线的个数和竖线的个数,去最小值。


#include <stdio.h>
#include <string.h>
#include <iostream>

using namespace std;
const int N = 105;

int n, cx[N], cy[N];

int main () {
	int nx = 0, ny = 0, xi, yi;
	memset(cx, 0, sizeof(cx));
	memset(cy, 0, sizeof(cy));

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &xi, &yi);
		if (cx[xi] == 0) nx++;
		if (cy[yi] == 0) ny++;
		cx[xi]++; cy[yi]++;
	}
	printf("%d\n", min(nx, ny));
	return 0;
}


你可能感兴趣的:(Codeforces 390A Inna and Alarm Clock(水题))