题目大意

给出一个折线图,有N条线段,你想要把这些线段分成几个集合,使得每个集合中任意两条线段不相交。

求最少集合数。

分析

喵帕斯:以下提及的所有折线均指横坐标在\([1,k]\)里的折线段。

思考两个折线若不相交会是什么情况?

对,即一个在上,一个在下(怎么有点奇怪呢)。

比如折线\(a\)在上,折线\(b\)在下,尝试对所有满足此关系的折线二元组连一条\(a\)到\(b\)的有向边,我们可以发现,使用一个集合可以走一条路径,那么题目求最小集合数,即求走最少的路径,师所有点全部被覆盖。

然后此题就转化为了最小路径覆盖问题,假设你已经会了该问题,然后就是喜闻乐见的匈牙利模板时间啦~

不会?

祝好梦。

#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
const int N = 200 + 5;
const int M = 10000 + 5; inline int read(){
int f = 1, x = 0; char ch;
do { ch = getchar(); if (ch == '-') f = -1; } while (ch < '0' || ch > '9');
do {x = (x << 3) + (x << 1) + ch - '0'; ch = getchar(); } while (ch >= '0' && ch <= '9');
return f * x;
} inline void write(int x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
} inline int max(int a, int b) { return a < b ? b : a; } inline int min(int a, int b) { return a < b ? a : b; } struct Graph {
int to[M << 1], nxt[M << 1], head[N], cnt;
inline void add(int x, int y) {
++cnt;
to[cnt] = y, nxt[cnt] = head[x], head[x] = cnt;
return;
}
}G;
int t, n, k, price[N][30], op, tot;
int vis[N], match[N], bj[N];
inline bool dfs(int u) {
for (int i = G.head[u];i;i = G.nxt[i]) {
int v = G.to[i];
if (!vis[v]) {
vis[v] = 1;
if (!match[v] || dfs(match[v])) {
match[v] = u, bj[u] = v;
return 1;
}
}
}
return 0;
} int rate[N];
inline bool cmp(const int &x, const int &y) {
return price[x][0] > price[y][0];
} inline bool can(int u, int v) {
for (int i = 1;i <= k; ++i) {
if (price[u][i] <= price[v][i]) return 0;
}
return 1;
} int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
t = read();
while (t --) {
n = read(), k = read();
memset(bj, 0, sizeof bj);
memset(G.head, 0, sizeof G.head);
memset(match, 0, sizeof match);
memset(price, 0, sizeof price);
G.cnt = 0;
for (int i = 1;i <= n; ++i) {
for (int j = 1;j <= k; ++j) {
price[i][j] = read();
price[i][0] = max(price[i][0], price[i][j]);
}
rate[i] = i;
} std :: sort(rate + 1, rate + 1 + n, cmp); for (int i = 1, u;i <= n; ++i) {
u = rate[i];
for (int j = i + 1, v;j <= n; ++j) {
v = rate[j];
if (can(u, v)) G.add(u, v);
}
} tot = 0;
for (int i = 1;i <= n; ++i) {
if (bj[i] == 0) {
memset(vis, 0, sizeof vis);
if (dfs(i)) tot ++;
}
}
printf("Case #%d: %d\n", ++op, n - tot);
}
return 0;
}

【简解】SP7556 Stock Charts的更多相关文章

  1. python ConfigParser、shutil、subprocess、ElementTree模块简解

    ConfigParser 模块 一.ConfigParser简介ConfigParser 是用来读取配置文件的包.配置文件的格式如下:中括号“[ ]”内包含的为section.section 下面为类 ...

  2. Stock Charts

    Description You're in the middle of writing your newspaper's end-of-year economics summary, and you' ...

  3. AC题目简解-数据结构

    A - Japan  POJ 3067 要两条路有交叉,(x1,y1)(x2,y2)那么需要满足:(x1-x2)*(y1-y2)<0判断出这是求逆序的问题 树状数组求逆序,先通过自定义的比较器实 ...

  4. UE4 RHI与Render模块简解

    UE4中的RHI指的是Render hardware interface,作用像Ogre里的RenderSystem,针对Dx11,Dx12,Opengl等等平台抽象出相同的接口,我们能方便能使用相同 ...

  5. zabbix基本监控各指标简解

    监控项目及使用模板 监控http和https: Template App HTTP Service     Template App HTTPS Service 监控cpu,内存,网络等: Templ ...

  6. (转)FFMPEG解码H264拼帧简解

    http://blog.csdn.net/ikevin/article/details/7649095 H264的I帧通常 0x00 0x00 0x00 0x01 0x67 开始,到下一个帧头开始之前 ...

  7. Spring ApplicationContext 简解

    ApplicationContext是对BeanFactory的扩展,实现BeanFactory的所有功能,并添加了事件传播,国际化,资源文件处理等.   configure locations:(C ...

  8. HTTP协议简解

    1.什么是http协议 http协议: 浏览器客户端 与  服务器端 之间数据传输的规范 2.查看http协议的工具 1)使用火狐的firebug插件(右键->查看元素->网络) 2)使用 ...

  9. linux netstat 命令简解

    Netstat 简介: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告.常见参数-a (all)显示所有选项,默认不显示LISTEN相 ...

随机推荐

  1. 如何设置网站的robots.txt

    做过网站优化的朋友都知道,搜索引擎蜘蛛爬行抓取网站时首先会去访问根目录下的robots.txt文件,如果robots文件存在,则会根据robots文件内设置的规则进行爬行抓取,如果文件不存在则会顺着首 ...

  2. k8s实现灰度发布

    灰度发布在实际生产部署中是经常被使用的方式,常规的方法是手动从前端LB(负载均衡)上将后端服务器摘掉,然后,停服务,最后上传代码,完成软连接更新.在使用CI/CD工具时,这个过程变得自动化了,我们只需 ...

  3. 云服务器搭建JDK+Tomcat+MySQL环境

    一.首先租赁一台云服务器(阿里云服务器或者腾讯云服务器) 其实可以在windows电脑上使用VMware workstation来安装虚拟机进行操作,毕竟云服务器低配也是很贵的.不过可以使用学生价去租 ...

  4. activeMQ 的启动 停止 查看状态

    1 启动 : 进入到activeMQ 的 bin 目录,执行   ./activemq start  开启 ,如下: 2  查看activeMQ 是不是启动的状态, ./activemq  statu ...

  5. java SDK服务端推送 --极光推送(JPush)

    网址:https://blog.csdn.net/duyusean/article/details/86581475 消息推送在APP应用中越来越普遍,来记录一下项目中用到的一种推送方式,对于Andr ...

  6. git clone指定branch或tag

    git clone指定branch或tag发布时间:October 28, 2018 // 分类: // No Comments 取完整: git clone https://github.com/a ...

  7. Xamarin.FormsShell基础教程(7)Shell项目关于页面的介绍

    Xamarin.FormsShell基础教程(7)Shell项目关于页面的介绍 轻拍标签栏中的About标签,进入关于页面,如图1.8和图1.9所示.它是对应用程序介绍的页面. 该页面源自Views文 ...

  8. django入门8之xadmin引入富文本和excel插件

    django入门8之xadmin引入富文本和excel插件 Xadmin引入富文本 插件的文档 https://xadmin.readthedocs.io/en/docs-chinese/make_p ...

  9. thinkphp项目部署在phpstudy里的nginx上

    朋友的一个thinkphp做的项目,让我帮他部署一下的,LINUX服务器,用宝塔. 第一台服务器,装上宝塔,宝塔里装NGINX,PHP5.6,再建立网站,绑定域名,访问成功,一切正常! 昨天试着给另一 ...

  10. IfcRoot

    IfcRoot is the most abstract and root class for all entity definitions that roots in the kernel or i ...