Inna and Alarm Clock CodeForces - 390A

35 篇文章 1 订阅
7 篇文章 0 订阅

Inna loves sleeping very much, so she needs n alarm clocks in total to wake up. Let’s suppose that Inna’s room is a 100 × 100 square with the lower left corner at point (0, 0) and with the upper right corner at point (100, 100). Then the alarm clocks are points with integer coordinates in this square.

The morning has come. All n alarm clocks in Inna’s room are ringing, so Inna wants to turn them off. For that Inna has come up with an amusing game:

First Inna chooses a type of segments that she will use throughout the game. The segments can be either vertical or horizontal.
Then Inna makes multiple moves. In a single move, Inna can paint a segment of any length on the plane, she chooses its type at the beginning of the game (either vertical or horizontal), then all alarm clocks that are on this segment switch off. The game ends when all the alarm clocks are switched off.
Inna is very sleepy, so she wants to get through the alarm clocks as soon as possible. Help her, find the minimum number of moves in the game that she needs to turn off all the alarm clocks!

Input
The first line of the input contains integer n (1 ≤ n ≤ 105) — the number of the alarm clocks. The next n lines describe the clocks: the i-th line contains two integers xi, yi — the coordinates of the i-th alarm clock (0 ≤ xi, yi ≤ 100).

Note that a single point in the room can contain any number of alarm clocks and the alarm clocks can lie on the sides of the square that represents the room.

Output
In a single line print a single integer — the minimum number of segments Inna will have to draw if she acts optimally.

Examples
Input
4
0 0
0 1
0 2
1 0
Output
2
Input
4
0 0
0 1
1 0
1 1
Output
2
Input
4
1 1
1 2
2 3
3 3
Output
3
Note
In the first sample, Inna first chooses type “vertical segments”, and then she makes segments with ends at : (0, 0), (0, 2); and, for example, (1, 0), (1, 1). If she paints horizontal segments, she will need at least 3 segments.

In the third sample it is important to note that Inna doesn’t have the right to change the type of the segments during the game. That’s why she will need 3 horizontal or 3 vertical segments to end the game.
题目大意:给出一些点,表示该点上有灯,每次可以关掉一排或者一竖的灯,问说最少需要关几次。
解题思路:水题,计算出横线的个数和竖线的个数,去最小值。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
    int n;
    int a[105][105];
    while(cin>>n&&n!=EOF)
    {
        memset(a,0,sizeof(a));
        for(int i=0;i<n;i++)
        {
            int x,y;
            cin>>x>>y;
            a[x][y]=1;
        }
        int n1=0,n2=0;
        for(int i=0;i<=100;i++)
        {
            for(int j=0;j<=100;j++)
            {
                if(a[i][j]==1)
                {
                    n1++;
                    break;
                }
            }
        }
        for(int i=0;i<=100;i++)
        {
            for(int j=0;j<=100;j++)
            {
                if(a[j][i]==1)
                {
                    n2++;
                    break;
                }
            }
        }
        int s=min(n1,n2);
        cout<<s<<endl;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值