题目链接:http://codeforces.com/contest/390/problem/A
题意:设置n个闹钟,给你每个闹钟的位置,选择竖列消除或者横行消除(只能用一种),问你关闭所有闹钟最小的操作数;
思路:横着扫一遍,竖着扫一遍,求较小值即可。
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5+10;
struct node
{
int x, y;
}p[N];
int n;
bool cmp1(node b, node c)
{
if(b.x != c.x) return b.x < c.x;
}
bool cmp2(node b, node c)
{
if(b.y != c.y) return b.y < c.y;
}
int main()
{
scanf("%d", &n);
for(int i = 0; i < n; i++)
{
scanf("%d%d", &p[i].x, &p[i].y);
}
int ans1 = 1, ans2 = 1;
sort(p, p+n, cmp1);
for(int i = 1; i < n; i++)
{
if(p[i].x == p[i-1].x)continue;
else ans1++;
}
sort(p, p+n, cmp2);
for(int i = 1; i < n; i++)
{
if(p[i].y == p[i-1].y) continue;
else ans2++;
}
int ans = min(ans1, ans2);
printf("%d\n", ans);
return 0;
}