传送门: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核心API

    在本教程中,我们将介绍学习Meteor核心API. 如果你想限制代码只在服务器或客户端可以使用下面的代码运行 - meteorApp.js if (Meteor.isClient) { // Code ...

  2. [Node.js] Write or Append to a File in Node.js with fs.writeFile and fs.writeFileSync

    In node.js, you can require fs, and then call fs.writeFile with the filename, and data to write to t ...

  3. 题目1011:最大连续子序列 O(n)

    题目大意:给出一系列的数字.要求你输出这些数字的最大连续和,并输出构成这个最大连续和的第一个数和最后一个数 解题思路:用一个变量维护最大连续和 假设当前这个变量小于0的话,就表示这个变量仅仅会拉低连续 ...

  4. cocos2dx 制作单机麻将(五)

    cocos2dx 制作单机麻将(五) 麻将逻辑6 最基础的4人麻将逻辑(轮流循环出牌, 之前学的都能用上  跑起来了!!!) 最基础的麻将逻辑 依据自己须要 设置麻将人数GAME_PLAYER 基本流 ...

  5. python 多线程中同步的小样例

    #!/usr/bin/python # -*- coding: UTF-8 -*- # 在一个资源池中.获取资源 # Author: zhang # Date: 2015-7-27 import ti ...

  6. php验证邮箱

    <?php if(isset($_POST['email'])){ $email = $_POST['email']; if(filter_var($email, FILTER_VALIDATE ...

  7. uva live 4394 String painter 区间dp

    // uva live 4394 String painter // // 这一题是训练指南上dp专题的习题,初看之下认为仅仅是稍微复杂了一点 // 就敲阿敲阿敲,两个半小时后,发现例子过了.然而自己 ...

  8. [转] 买彩票的利器--gun

    源链接 还在自己买彩票吗,有个现成的:GNU shuf命令. shuf -i - -n | 这样就会产生两组彩票(1~36个数字任选) 当然还可以派其他用途,比如: shuf -e clubs hea ...

  9. Hibernate中二级缓存指的是什么?

    一.一级缓存.二级缓存的概念解释 (1)一级缓存就是Session级别的缓存,一个Session做了一个查询操作,它会把这个操作的结果放在一级缓存中,如果短时间内这个 session(一定要同一个se ...

  10. MVC Web Api 发布到Azure报错

    I fixed this by reinstalling the NuGet package, which corrects broken dependencies. From the package ...