zoukankan      html  css  js  c++  java
  • Codeforces 390A( 模拟题)

    Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

     Status

    Description

    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 xiyi — 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.

    Sample Input

    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

    Hint

    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.

    Source

    题意:一个二维矩阵,每个格子都有一个数,每次可以让一列或者一行的数全变成0。目的是让他们全变成0,问最少需要几步。
    题解:选择行和列中有数的条数小的那一个,只关行或者只关列的,如果该行或者该列全都为0则不计入次数,就是全是0的条不用关。
    #include <iostream>
    #include <stdlib.h>
    #include <stdio.h>
    #include <algorithm>
    #include <string.h>
    #include <math.h>
    using namespace std;
    typedef long long ll;
    int main()
    {
        int i,j,m,n,sum1,sum2,x,y,a[100005],b[100005];
        while (cin>>n)
        {
            sum1=0;
            sum2=0;
            memset(a,0,sizeof(a));
            memset(b,0,sizeof(b));
            for (i=0;i<n;i++)
            {
                cin>>x>>y;
                a[x]=1;
                b[y]=1;
            }
            for (i=0;i<105;i++)
            if (a[i])
            sum1++;
            for (i=0;i<105;i++)
            if (b[i])
            sum2++;
            if (sum1<sum2)
            cout<<sum1<<endl;
            else
            cout<<sum2<<endl;
        }
        return 0;
    }
     
  • 相关阅读:
    delphi 遇到Line too long(more than 1023 characters问题,将原有代码分离出过程来调用,调用使用 过程名字(self) 调用
    sql 从房间号中或从含有几个"-"间隔的字符串中,截取楼层数,或截取第几个"-"后的前几个字符或数字
    delphi mac地址 网卡地址获取,如果有无线网卡连接情况,mac地址随机获取某个本地连接网卡地址,要都写进去判断
    delphi 输入年月判断天数,判断指定年份与月份判断当月有多少天
    在SQL SERVER中查询数据库中第几条至第几条之间的数据SQL语句写法
    手动修改PHP页面返回状态码
    PHPExcel 导出包含图片excel
    windows apache启动报错
    mysql正则查询 模糊查询
    symfony安装总结
  • 原文地址:https://www.cnblogs.com/Ritchie/p/5425003.html
Copyright © 2011-2022 走看看