[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 ...
随机推荐
- .NET中lock的使用方法及注意事项[转]
标准-->ms官方: http://msdn.microsoft.com/zh-cn/library/c5kehkcz(v=vs.90).aspx A.为什么不要 "lock(this ...
- [LeetCode][Java] Remove Duplicates from Sorted List II
题意: Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct ...
- FancyCoverFlow
https://github.com/davidschreiber/FancyCoverFlow
- [更新Github地址]python学习,自己写了个简单聊天工具mychat
最近在学习python,自己写了个最最简单的聊天工具mychatv0.1. 第一版,完成基本的聊天功能. GUI用的是自带的TKinter,用到的模块主要就是socket(网络编程), thread( ...
- /etc/profile与/etc/bashrc、交互式与非交互式、login与non-login shell的差别
线上的memcached又挂了.仍然没有得到core文件. 排查原因,同事发现启动memcached的脚本存在可疑问题. 问题一:没有设置memcached工作文件夹,有可能core dump时没有工 ...
- 内存转储文件 Memory.dmp
https://baike.sogou.com/v63435711.htm?fromTitle=内存转存文件 内存转储是用于系统崩溃时,将内存中的数据转储保存在转储文件中,供给有关人员进行排错分析用途 ...
- WinPE:创建 USB 可引导驱动器
https://msdn.microsoft.com/zh-cn/library/windows/hardware/dn938386(v=vs.85).aspx
- Lightoj 1018 - Brush (IV)
1018 - Brush (IV) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Muba ...
- ubuntu12.04 64位系统配置jdk1.6和jdk-6u20-linux-i586.bin下载地址
1:下载地址http://code.google.com/p/autosetup1/downloads/detail?name=jdk-6u20-linux-i586.bin&can=2&am ...
- centOS安装mysql---glibc方式
写在前面: 首先,centos是自己集成mysql的.但是我要用的服务器人家没给装. 其次,centos是可以yum安装mysql的,我很高兴而且轻松的用yum把mysql安装上了.但是,运行的时候很 ...