传送门: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【二分图】的更多相关文章

  1. [USACO 2011 Dec Gold] Cow Calisthenics【二分】

    Problem 1: Cow Calisthenics [Michael Cohen, 2010] Farmer John continues his never-ending quest to ke ...

  2. [USACO 2011 Nov Gold] Above the Median【逆序对】

    传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=91 这一题我很快的想出了,把>= x的值改为1,< x的改为- ...

  3. Luogu P3033 [USACO11NOV]牛的障碍Cow Steeplechase(二分图匹配)

    P3033 [USACO11NOV]牛的障碍Cow Steeplechase 题意 题目描述 --+------- -----+----- ---+--- | | | | --+-----+--+- ...

  4. 【BZOJ】【1046】/【POJ】【3613】【USACO 2007 Nov】Cow Relays 奶牛接力跑

    倍增+Floyd 题解:http://www.cnblogs.com/lmnx/archive/2012/05/03/2481217.html 神题啊= =Floyd真是博大精深…… 题目大意为求S到 ...

  5. 洛谷 - P3033 - 牛的障碍Cow Steeplechase - 二分图最大独立集

    https://www.luogu.org/fe/problem/P3033 二分图最大独立集 注意输入的时候控制x1,y1,x2,y2的相对大小. #include<bits/stdc++.h ...

  6. [USACO 2012 Feb Gold] Cow Coupons【贪心 堆】

    传送门1:http://www.usaco.org/index.php?page=viewproblem2&cpid=118 传送门2:http://www.lydsy.com/JudgeOn ...

  7. 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 ...

  8. 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 ...

  9. 【POJ3612】【USACO 2007 Nov Gold】 1.Telephone Wire 动态调节

    意甲冠军: 一些树高给出.行一种操作:把某棵树增高h,花费为h*h. 操作完毕后连线,两棵树间花费为高度差*定值c. 求两种花费加和最小值. 题解: 跟NOIP2014 D1T3非常像. 暴力动规是O ...

随机推荐

  1. Meteor check

    check方法用于检查参数或类型是否匹配模式. 安装check包 打开命令提示符窗口,并安装该软件包. C:\Users\Administrator\Desktop\meteorApp>mete ...

  2. 将oracle10g 升级至10.2.0.4

    http://blog.csdn.net/launch_225/article/details/7221489 一.单实例环境,全时长一个半钟多. 详细图文说明到这下载 1.停止所有oracle相关进 ...

  3. [转]JAVA对象容器

    要用Java实现记事本的功能.首先列出记事本所需功能: 可以添加记录(字符串): 可以获得记录条数: 可以删除其中某一条记录: 可以获得指定第几条的记录: 可以列出所有的记录. 如果这个记事本是某个大 ...

  4. centos编辑界面和图形界面登陆切换设置

    输入命令 vi /etc/inittab 到最后一行.把5改成3 保存退出. 各数字的含义: #   0 - halt (Do NOT set initdefault to this)         ...

  5. apache下配置认证用户

    有时候我们须要给我apacheserver下制定的文件夹加上用户认证,方便一些而用户进行文件的浏览.配置例如以下: 1 设置用户 1 htpasswd -c file_path user_name 回 ...

  6. CronTab命令实例

    每2分钟 将date写入到time.log(以下的为奇数分钟运行) */2 * * * * date >> ~/time.log 1-59/2 * * * * date >> ...

  7. Linux如何查看进程等常用命令

    1.查进程    ps命令查找与进程相关的PID号:    ps a 显示现行终端机下的所有程序,包括其他用户的程序.    ps -A 显示所有程序.    ps c 列出程序时,显示每个程序真正的 ...

  8. 设置Table边框的CSS

    <!DOCTYPE html> <html> <head> <style> table, td, th { border: 1px solid blac ...

  9. Lightoj 1009 - Back to Underworld

    1009 - Back to Underworld    PDF (English) Statistics Forum Time Limit: 4 second(s) Memory Limit: 32 ...

  10. SQLite数据库框架--FMDB简单介绍

    1.什么是FMDB FMDB是iOS平台的SQLite数据库框架 FMDB以OC的方式封装了SQLite的C语言API 2.FMDB的优点 使用起来更加面向对象,省去了很多麻烦.冗余的C语言代码 对比 ...