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

Submit 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[],b[];
while (cin>>n)
{
sum1=;
sum2=;
memset(a,,sizeof(a));
memset(b,,sizeof(b));
for (i=;i<n;i++)
{
cin>>x>>y;
a[x]=;
b[y]=;
}
for (i=;i<;i++)
if (a[i])
sum1++;
for (i=;i<;i++)
if (b[i])
sum2++;
if (sum1<sum2)
cout<<sum1<<endl;
else
cout<<sum2<<endl;
}
return ;
}

Codeforces 390A( 模拟题)的更多相关文章

  1. CodeForces - 427B (模拟题)

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

  2. CodeForces - 404B(模拟题)

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

  3. CodeForces - 404A(模拟题)

    Valera and X Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit ...

  4. CodeForces 1B 模拟题。

    H - 8 Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  5. Educational Codeforces Round 2 A. Extract Numbers 模拟题

    A. Extract Numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/600/pr ...

  6. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  7. Codeforces Beta Round #7 B. Memory Manager 模拟题

    B. Memory Manager 题目连接: http://www.codeforces.com/contest/7/problem/B Description There is little ti ...

  8. Codeforces Beta Round #5 B. Center Alignment 模拟题

    B. Center Alignment 题目连接: http://www.codeforces.com/contest/5/problem/B Description Almost every tex ...

  9. Codeforces Beta Round #3 C. Tic-tac-toe 模拟题

    C. Tic-tac-toe 题目连接: http://www.codeforces.com/contest/3/problem/C Description Certainly, everyone i ...

随机推荐

  1. mvc:resources

    springmvc 配置静态文件 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mv ...

  2. HttpClient教程

    2.1.持久连接 两个主机建立连接的过程是很复杂的一个过程,涉及到多个数据包的交换,并且也很耗时间.Http连接需要的三次握手开销很大,这一开销对于比较小的http消息来说更大.但是如果我们直接使用已 ...

  3. ci默认控制器

    默认控制器 前面提到,如果在请求中没有指明具体的控制器,CI将会把页面重定向到一个系统默认的页面.这个默认页面可以自己设定,它存放在如下地址:/system/application/config/ro ...

  4. tomcat管理员配置

    纸上得来终觉浅,绝知此事要躬行 博客园 首页 新闻 新随笔 联系 管理 随笔- 458  文章- 0  评论- 38  Tomcat的Manager显示403 Access Denied   管理to ...

  5. --Dirring love 音乐(01背包问题)

    解题思路: dp[i][j] 前 i 首歌放入 j 容量中的最大热情度. 前 i 首歌 放到 j 容量中 dp[i][j]= dp[i-1][j-m[i]]+r[i]   (注意:如果 j 容量 &l ...

  6. 使用key链接远程Git仓库

    使用密钥来访问Git仓库比密码安全多了,只要把公钥配置在远程端,把密钥放到~/.ssh/里以id_rsa命名即可. 不过有人要问如果有多个仓库,而且用了不同密钥怎么办? 这时候可以在~/.ssh/文件 ...

  7. mysql 视图(view)

    什么是视图 视图是从一个或多个表中导出来的表,是一种虚拟存在的表. 视图就像一个窗口,通过这个窗口可以看到系统专门提供的数据. 这样,用户可以不用看到整个数据库中的数据,而之关心对自己有用的数据. 数 ...

  8. java.net.SocketException:Software caused connection abort: recv failed 异常分析 +socket客户端&服务端代码

    java.net.SocketException:Software caused connection abort: recv failed 异常分析 分类: 很多的技术 2012-01-04 12: ...

  9. Socket网络编程(1)

    TCP/IP 简单介绍 应用层 (Application):应用层是个很广泛的概念,有一些基本相同的系统级 TCP/IP 应用以及应用协议,也有许多的企业商业应用和互联网应用. 传输层 (Transp ...

  10. jquery中$.ajax

    $.ajax({ type : 'post', url : '/edm/testEmail.php', data: {tId:tId, sId:sId ,testEmail:testEmail}, d ...