当前位置:网站首页>P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
2022-07-06 04:03:00 【Zhong Zhongzhong】
https://www.luogu.com.cn/problem/P3033
P3033 [USACO11NOV]Cow Steeplechase G
Cried and cried , I originally wanted to watch online classes , This inscription cost me a lot 2 hours .... Fortunately, it's a blue question , Or you'll lose a lot
Seriously summarize :
1. First 250250 Data over 10000 , Be sure to use the chained forward star method to save the map .
2. The difficulty of this problem lies in the establishment of graphics , Take the vertical line segment as the upper node , The lower node intersecting with it establishes a line segment ; The horizontal line serves as the lower node , Find the maximum matching tree , This is the minimum vertex covering
3.n- This value , The rest of the line segments have nothing to do with each other , That's the answer. .
4. The rest is the template of Hungarian algorithm *
#include <bits/stdc++.h>
#define y1 y11
using namespace std;
const int inf=0x3f3f3f3f;
const int maxn=1e6+5;
int link[maxn],n,head[maxn],cnt;
int p[maxn],x1[maxn],y1[maxn],x2[maxn],y2[maxn],n1;
bool used[maxn];
struct node
{
int to,nxt;
}e[maxn];
void add_edge(int from,int to)
{
e[++cnt].to=to;
e[cnt].nxt=head[from];
head[from]=cnt;
}
bool dfs(int u)
{
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].to;
if(!used[v])
{
used[v]=1;
if(link[v]==-1||dfs(link[v]))
{
link[v]=u;
return 1;
}
}
}
return 0;
}
int hungary()
{
memset(link,-1,sizeof(link));
int ret=0;
for(int i=1;i<=n;i++)
{
if(p[i]==2)
continue;
memset(used,0,sizeof(used));
if(dfs(i))
ret++;
}
return ret;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d%d",&x1[i],&y1[i],&x2[i],&y2[i]);
if(x1[i]>x2[i]) swap(x1[i],x2[i]);
if(y1[i]>y2[i]) swap(y1[i],y2[i]);
if(x1[i]==x2[i]) p[i]=1,n1++; // Number of vertical points
else
p[i]=2;
}
for(int i=1;i<=n;i++)
{
for(int j=i+1;j<=n;j++)
{
if(p[i]==1&&p[j]==2)
{
if(x1[i]>=x1[j]&&x2[i]<=x2[j]&&y1[i]<=y1[j]&&y2[i]>=y2[j])
add_edge(i,n1+j);
}
else if(p[i]==2&&p[j]==1)
{
if(x1[i]<=x1[j]&&x2[i]>=x2[j]&&y1[i]>=y1[j]&&y2[i]<=y2[j])
add_edge(j,n1+i);
}
}
}
printf("%d\n",n-hungary());
return 0;
}
边栏推荐
- 51nod 1130 n factorial length V2 (Stirling approximation)
- [analysis of variance] single factor analysis and multi factor analysis
- 【可调延时网络】基于FPGA的可调延时网络系统verilog开发
- ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
- 潘多拉 IOT 开发板学习(HAL 库)—— 实验9 PWM输出实验(学习笔记)
- Cf603e pastoral oddities [CDQ divide and conquer, revocable and search set]
- Failure causes and optimization methods of LTE CSFB
- [meisai] meisai thesis reference template
- Microkernel structure understanding
- An article will give you a comprehensive understanding of the internal and external components of "computer"
猜你喜欢
Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did
MySQL reads missing data from a table in a continuous period of time
Ks003 mall system based on JSP and Servlet
How do we make money in agriculture, rural areas and farmers? 100% for reference
Solution to the problem that the root account of MySQL database cannot be logged in remotely
记一次excel XXE漏洞
Factors affecting user perception
MySql數據庫root賬戶無法遠程登陸解决辦法
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
【按键消抖】基于FPGA的按键消抖模块开发
随机推荐
[Zhao Yuqiang] deploy kubernetes cluster with binary package
[FPGA tutorial case 11] design and implementation of divider based on vivado core
TCP/IP协议里面的网关地址和ip地址有什么区别?
MySQL transaction isolation level
SSTI template injection explanation and real problem practice
C (thirty) C combobox listview TreeView
Failure causes and optimization methods of LTE CSFB
pd. to_ numeric
/usr/bin/gzip: 1: ELF: not found/usr/bin/gzip: 3: : not found/usr/bin/gzip: 4: Syntax error:
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
Microkernel structure understanding
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
No qualifying bean of type ‘......‘ available
[analysis of variance] single factor analysis and multi factor analysis
[optimization model] Monte Carlo method of optimization calculation
阿里测试师用UI自动化测试实现元素定位
Determine which week of the month the day is
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
C#(二十七)之C#窗体应用
Take you to wechat applet development in 3 minutes