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. 史上最详细的Android Studio系列教程四--Gradle基础

    https://segmentfault.com/a/1190000002439306#articleHeader0

  2. c# 闭包 小例

    class Program { static void fnnn() { string[] k = new string[] { "x", "y", " ...

  3. JavaScript的apply和call方法及其区别

    参考资料: http://blog.csdn.net/myhahaxiao/article/details/6952321 apply和call能“劫持”其他对象的方法来执行,其形参如下: apply ...

  4. Spring MVC GET 从客户端数据到服务器端的乱码和服务器端数据到客户端的乱码

    参考资料:http://m.oschina.net/blog/376339 乱码的本质是涉及到编解码的几个过程所用的编码方式不一样. 一.从服务端到客户端 在整个服务器端数据返回到浏览器的过程中,涉及 ...

  5. Tomcat入门指南

    转自javaresearch.com由timgball 整理 Tomcat是一个免费的开源Web服务器,最新版本是5.5.1,支持Servlet2.4,JSP2.0,非常适合初学者学习Java Web ...

  6. C++小思

    Bjarne那稀疏的棕褐色头发, 有点红的眼睛, 这个可爱的好老头, 感觉他更应该是一个哲学家, 因为他用编程的语言C++ 揭示了我们这个纷繁复杂世界的本质: 对象. 对的, 世界是由对象组成的, 并 ...

  7. avalon框架,简单的MVVM

    今天我又要挑战一次一个高大上的公司了 但是看着jd有点忧伤了要求如下 基本要求:1.熟悉 HTML / CSS / JS 并有良好的代码风格:2.理解 Web 标准,语义化,可以解决主流浏览器及不同版 ...

  8. cc表示Cocos核心,ccs代表CocoStudio,ccui代表CocoStudio的UI控件

    cc表示Cocos核心,ccs代表CocoStudio,ccui代表CocoStudio的UI控件

  9. Spring常用的接口和类(三)

    一.CustomEditorConfigurer类 CustomEditorConfigurer可以读取实现java.beans.PropertyEditor接口的类,将字符串转为指定的类型.更方便的 ...

  10. python网络编程之最简单的单工通信

    tcp_server.py from socket import * server = socket(AF_INET, SOCK_STREAM) server.bind(('',12345)) ser ...