当前位置:网站首页>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;
}
边栏推荐
- Yyds dry goods inventory web components series (VII) -- life cycle of custom components
- [FPGA tutorial case 11] design and implementation of divider based on vivado core
- 《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
- [analysis of variance] single factor analysis and multi factor analysis
- Chinese brand hybrid technology: there is no best technical route, only better products
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
- C language -- structs, unions, enumerations, and custom types
- 【按键消抖】基于FPGA的按键消抖模块开发
- MySql数据库root账户无法远程登陆解决办法
猜你喜欢

Exchange bottles (graph theory + thinking)

math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)

Plus d'un milliard d'utilisateurs de grandes entreprises comme Facebook ont été compromis, il est temps de se concentrer sur le did

math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi

C mouse event and keyboard event of C (XXVIII)

【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用

Align items and align content in flex layout
![[adjustable delay network] development of FPGA based adjustable delay network system Verilog](/img/82/7ff7f99f5164f91fab7713978cf720.png)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
![[Key shake elimination] development of key shake elimination module based on FPGA](/img/47/c3833c077ad89d4906e425ced945bb.png)
[Key shake elimination] development of key shake elimination module based on FPGA

cookie,session,Token 这些你都知道吗?
随机推荐
Introduction to data types in MySQL
简易博客系统
MySQL 中的数据类型介绍
Determine which week of the month the day is
【leetcode】1189. Maximum number of "balloons"
Python book learning notes - Chapter 09 section 01 create and use classes
Take you to wechat applet development in 3 minutes
Basic concepts of LTE user experience
[FPGA tutorial case 11] design and implementation of divider based on vivado core
记一次excel XXE漏洞
Prime Protocol宣布在Moonbeam上的跨链互连应用程序
MySQL about self growth
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]
[meisai] meisai thesis reference template
在 .NET 6 中使用 Startup.cs 更简洁的方法
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL master-slave replication
Simple blog system
Differential GPS RTK thousand search
Hashcode and equals