[USACO 2011 Nov Gold] Cow Steeplechase【二分图】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=93
很容易发现,这是一个二分图的模型。竖直线是X集,水平线是Y集,若某条竖直线与水平线相交,则连边。由于目的是要没有任何两条线相交,所以二分图的边的两端不能同时取,就是要求一个二分图的最大独立集,which equals to N - 最大匹配。
然而啊然而,仍然没有一A!此题只是说给出线段两端点的坐标,并没有说x1一定<x2,y1一定<y2。。。
可以说这是本次月赛金足最水的题,竟然放在第三题,吃鲸。。。
#include <cstdio>
#include <cstring> const int maxn = 255; int link[maxn], n, idxx, idxy, match, tem;
bool cover[maxn], g[maxn][maxn];
struct st {
int x1, y1, x2, y2;
} x[maxn], y[maxn], t; bool fnd(int i) {
for (int j = 1; j <= idxy; ++j) {
if (!cover[j] && g[i][j]) {
cover[j] = 1;
if (!link[j] || fnd(link[j])) {
link[j] = i;
return true;
}
}
}
return false;
} int main(void) {
freopen("steeple.in", "r", stdin);
freopen("steeple.out", "w", stdout);
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d%d%d%d", &t.x1, &t.y1, &t.x2, &t.y2);
if (t.x1 == t.x2) {
if (t.y1 > t.y2) {
tem = t.y1;
t.y1 = t.y2;
t.y2 = tem;
}
x[++idxx] = t;
}
else {
if (t.x1 > t.x2) {
tem = t.x1;
t.x1 = t.x2;
t.x2 = tem;
}
y[++idxy] = t;
}
} for (int i = 1; i <= idxx; ++i) {
for (int j = 1; j <= idxy; ++j) {
if (x[i].x1 >= y[j].x1 && x[i].x1 <= y[j].x2 &&
y[j].y1 >= x[i].y1 && y[j].y1 <= x[i].y2) {
g[i][j] = 1;
}
}
} for (int i = 1; i <= idxx; ++i) {
memset(cover, 0, sizeof cover);
if (fnd(i)) {
++match;
}
}
printf("%d\n", n - match);
return 0;
}
(ps,我写比较长的函数的时候总是在最后忘记return,导致一些奇奇怪怪的错误,以后我需要强制自己写完签名后立即写上return啥!)
[USACO 2011 Nov Gold] Cow Steeplechase【二分图】的更多相关文章
- [USACO 2011 Dec Gold] Cow Calisthenics【二分】
Problem 1: Cow Calisthenics [Michael Cohen, 2010] Farmer John continues his never-ending quest to ke ...
- [USACO 2011 Nov Gold] Above the Median【逆序对】
传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=91 这一题我很快的想出了,把>= x的值改为1,< x的改为- ...
- Luogu P3033 [USACO11NOV]牛的障碍Cow Steeplechase(二分图匹配)
P3033 [USACO11NOV]牛的障碍Cow Steeplechase 题意 题目描述 --+------- -----+----- ---+--- | | | | --+-----+--+- ...
- 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑
倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到 ...
- 洛谷 - P3033 - 牛的障碍Cow Steeplechase - 二分图最大独立集
https://www.luogu.org/fe/problem/P3033 二分图最大独立集 注意输入的时候控制x1,y1,x2,y2的相对大小. #include<bits/stdc++.h ...
- [USACO 2012 Feb Gold] Cow Coupons【贪心 堆】
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=118 传送门2:http://www.lydsy.com/JudgeOn ...
- bzoj2581 [USACO 2012 Jan Gold] Cow Run【And-Or Tree】
传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=110 传送门2:http://www.lydsy.com/JudgeOn ...
- USACO 2011 February Silver Cow Line /// 康拓展开模板题 oj22713
题目大意: 输入n k,1-n的排列,k次操作 操作P:输入一个m 输出第m个排列 操作Q:输入一个排列 输出它是第几个排列 Sample Input 5 2P3Q1 2 5 3 4 Sample O ...
- 【POJ3612】【USACO 2007 Nov Gold】 1.Telephone Wire 动态调节
意甲冠军: 一些树高给出.行一种操作:把某棵树增高h,花费为h*h. 操作完毕后连线,两棵树间花费为高度差*定值c. 求两种花费加和最小值. 题解: 跟NOIP2014 D1T3非常像. 暴力动规是O ...
随机推荐
- [React] PureComponent in React
In this lesson, you will learn how to use PureComponent in React to reduce the number of times your ...
- HDU 1201 18岁生日 【日期】
18岁生日 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU 2896 病毒侵袭 (AC自己主动机)
pid=2896">http://acm.hdu.edu.cn/showproblem.php?pid=2896 病毒侵袭 Time Limit: 2000/1000 MS (Java ...
- sql server 系统常用函数:聚合函数 数学函数 字符串函数 日期和时间函数和自定义函数
一.系统函数 1.聚合函数 聚合函数常用于GROUP BY子句,在SQL Server 2008提供的所有聚合函数中,除了COUNT函数以外,聚合函数都会忽略空值AVG.COUNT.COUNT_BIG ...
- STL_算法_最小值和最大值(min_element、max_element)
C++ Primer 学习中... 简单记录下我的学习过程 (代码为主) min_element.max_element 找最小.最大值. 非常easy没什么大作用 #include<iost ...
- GitHub Pages使用入门
1.什么是GitHub Pages GitHub Pages可以当做项目的Websites,GitHub Pages有两种最基本的用法: 作为你自己(或者组织)的网站(访问地址示例:http://us ...
- Android NDK生成及连接静态库与动态库
对于Android应用开发,大部分情况下我们使用Java就能完整地实现一个应用.但是在某些情况下,我们需要借助C/C++来写JNI本地代码.比如,在使用跨平台的第三方库的时候:为了提升密集计算性能的时 ...
- js的location对象
js的location对象 location基础知识 BOM(浏览器对象模型)中最有用的对象之一就是location,它是window对象和document对象的属性.location对象表示载入窗口 ...
- 将json文件转换成insert语句的sql文件
引入是要的maven依赖: <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <depend ...
- C# 反射 设置实体属性
C# 反射 设置实体属性 http://blog.csdn.net/cestarme/article/details/6548126 C#反射设置属性值和获取属性值 http://www.cnblog ...