当前位置:网站首页>Three lines (spring daily question 59)
Three lines (spring daily question 59)
2022-07-18 13:44:00 【sweetheart7-7】
Farmer John wants to monitor his with the new monitoring system he bought N N N A cow .
The first i i i The cow is in a position with integer coordinates ( x i , y i ) (x_i,y_i) (xi,yi).
No two cows occupy the same position .
John's surveillance system contains three special cameras , Each camera can observe all the cows along a vertical or horizontal line .
Please confirm whether John can reasonably set the placement of the three cameras , So that he can monitor all N N N A cow .
in other words , Please make sure that all... Can be placed through three vertical or horizontal lines N N N The location of the cows is completely covered .
Input format
The first line contains integers N N N.
Next N N N That's ok , Each line contains two integers x i , y i x_i,y_i xi,yi, The horizontal and vertical coordinates of the position of a cow .
Output format
If you can use three vertical or horizontal lines to place all N N N The location of the cows is completely covered , Please export 1 1 1, Otherwise output 0 0 0.
Data range
1 ≤ N ≤ 50000 , 1≤N≤50000, 1≤N≤50000,
0 ≤ x i , y i ≤ 1 0 9 0≤x_i,y_i≤10^9 0≤xi,yi≤109
sample input :
6
1 7
0 0
1 2
2 0
1 4
3 4
sample output :
1
Sample explanation
y = 0 , x = 1 , y = 4 y=0,x=1,y=4 y=0,x=1,y=4 It can cover the positions of all cows .
#include<iostream>
#include<unordered_set>
#define x first
#define y second
using namespace std;
const int N = 50010;
typedef pair<int, int> PII;
int n;
PII q[N];
unordered_set<int> row, col;
int dfs(int u, int cnt){
if(cnt > 3) return 0;
if(u == n) return 1;
if(row.count(q[u].x) || col.count(q[u].y))
return dfs(u + 1, cnt);
row.insert(q[u].x);
if(dfs(u + 1, cnt + 1)) return 1;
row.erase(q[u].x);
col.insert(q[u].y);
if(dfs(u + 1, cnt + 1)) return 1;
col.erase(q[u].y);
return 0;
}
int main(){
scanf("%d", &n);
for(int i = 0; i < n; i++)
scanf("%d%d", &q[i].x, &q[i].y);
printf("%d\n", dfs(0, 0));
return 0;
}
边栏推荐
- [deep learning] environment configuration of hands-on learning and deep learning
- Reduction of type
- DLS-12B/DC220V双位置继电器
- Esp8266+blinker+web distribution network
- layoutgan:generating graphic layouts with wiregrame discriminators
- 三匹马携手乾元公益基金会 | 炎夏送清凉,致敬坚守者 !
- DzzOffice_ Flowplayer player changes
- AB PLC学习笔记
- Dls-42/4-4 dc110v double position relay
- 312312dd
猜你喜欢

The second day of MATLAB learning (basic grammar, variables, commands and creating your own files)
![Guess the size of the number ii[what problem does dynamic planning solve?]](/img/a0/6f94899557df7aff18377411cc10a8.png)
Guess the size of the number ii[what problem does dynamic planning solve?]

备赛笔记:神经网络

What are MySQL's intentional shared locks, intentional exclusive locks, and deadlocks

How does Xishanju build a game industry assembly line with ones? | Ones industry practice

Halcon 3D create_ pose

Expert routine of BW conversion based on AMDP

【独立站运营】一分钟读懂跨境电商运营四大技巧!

Sword finger offer 10- I. Fibonacci sequence

Micro, m3o micro service series (I)
随机推荐
Test / develop programmers' humorous "self mockery"? Impression genre
Analysis of JSON operation examples in golang
Dls-42/4-4 dc110v double position relay
DLS-12B/DC220V双位置继电器
QTcpServer多线程实现
layoutgan:generating graphic layouts with wiregrame discriminators
leetcode - 面试题 02.05. 链表求和
Rust中的函数function与方法method的区别
The third day of MATLAB learning (data types, operators and various operations)
Function overloading
Research progress of transfer learning in medical image classification
单细胞文献学习(part4)--SCANPY: large-scale single-cell gene expression data analysis
idea 将dev分支代码合并到master类推
Dpr-34, AC220V double position relay
视频处理:视频抽样
Baccalais PLC change axis task scanning time and cycle position issue
After Jay Chou's co branded model, Fang Wenshan brought online shopping to promote the collection of "Hualiu" top-level co branded dolls
28K monthly salary for software testing interview questions for large factories (you can take away the test paper with the permission of the interviewer)
Hcip the next day
AB PLC学习笔记