Codeforces Round #229 (Div. 2)A. Inna and Alarm Clock
2014-02-12 12:00
771 查看
A. Inna and Alarm Clock
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
input
output
input
output
input
output
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<cstring>
using namespace std;
int s[110][110];
int main(){
int n,a,b,flag;
memset(s,0,sizeof(s));
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&a,&b);
s[a][b]=1;
}
int t1,t2,num1,num2;
t1=t2=n;
num1=num2=0;
for(int i=0;i<110;i++){
flag=0;
for(int j=0;j<110;j++){
if(s[i][j]==1){
flag=1;
t1--;
}
}
if(flag)
num1++;
if(t1==0)
break;
}
for(int i=0;i<110;i++){
flag=0;
for(int j=0;j<110;j++){
if(s[j][i]==1){
flag=1;
t2--;
}
}
if(flag)
num2++;
if(t2==0)
break;
}
printf("%d\n",min(num1,num2));
return 0;
}
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
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.
Sample test(s)
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 22 33 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<cstring>
using namespace std;
int s[110][110];
int main(){
int n,a,b,flag;
memset(s,0,sizeof(s));
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&a,&b);
s[a][b]=1;
}
int t1,t2,num1,num2;
t1=t2=n;
num1=num2=0;
for(int i=0;i<110;i++){
flag=0;
for(int j=0;j<110;j++){
if(s[i][j]==1){
flag=1;
t1--;
}
}
if(flag)
num1++;
if(t1==0)
break;
}
for(int i=0;i<110;i++){
flag=0;
for(int j=0;j<110;j++){
if(s[j][i]==1){
flag=1;
t2--;
}
}
if(flag)
num2++;
if(t2==0)
break;
}
printf("%d\n",min(num1,num2));
return 0;
}
相关文章推荐
- Codeforces Round #229 (Div. 2) A. Inna and Alarm Clock
- Codeforces Round #229 (Div. 2)C - Inna and Candy Boxes心得
- Codeforces Round #234 (Div. 2) A. Inna and Choose Options
- Codeforces Round #234 (Div. 2) B. Inna and New Matrix of Candies
- Codeforces Round #220 (Div. 2)C题:Inna and Dima(记忆化搜索+DP)
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding 拓扑排序
- Codeforces Round #430 (Div. 2) D. Vitya and Strange Lesson
- Codeforces Round #136 (Div. 1)C. Little Elephant and Shifts multiset
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2)——B纯暴力——Bear and Three Musketeers
- Codeforces Round #263 (Div. 1) A. Appleman and Toastman
- Codeforces Round #329 (Div. 2) B. Anton and Lines ([好题] 计算直线在区间是否有交点)
- 【Educational Codeforces Round 48 (Rated for Div. 2) D】Vasya And The Matrix
- 【Codeforces Round 169 (Div 2) E】【数据结构区间维护】Little Girl and Problem on Trees 大菊花树的距离性修改查询
- 【前缀和 && 思维转换】ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined)Molly's Chemicals
- Codeforces Round #174 (Div. 2) Cows and Sequence(线段树)
- ICM Technex 2017 and Codeforces Round #400 (Div. 1 + Div. 2, combined) C. Molly's Chemicals
- Codeforces Round #206 (Div. 2) E-Vasya and Beautiful Arrays
- 【Codeforces Round 354 (Div 2)E】【数学 多项式除法 讨论】The Last Fight Between Human and AI 多项式除以x-k是否值整除
- Codeforces Round #253 (Div. 2)——Borya and Hanabi
- Educational Codeforces Round 37 (Rated for Div. 2) F. SUM and REPLACE(线段树,区间更新)