题目大意

给出一个折线图,有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. UDF——Fluent与Matlab数据耦合

    本文编译工具:VC++ UDF Studio 该插件可以直接在Visual Studio中一键编译.加载.调试UDF源码,极大提高编写排错效率,且支持C++,MFC,Windows API和第三方库, ...

  2. 阿里云ECS服务器相关配置以及操作---上(初学者)

    最近买了一台阿里云的ECS服务器 linux系统 centos镜像,把我相关的一些操作记录下来,供大家参考,不足之处欢迎指正. 首先买的过程就不用介绍了,根据自己的实际需要选择自己想要的配置,点击付钱 ...

  3. 在 RPA10.X 运行异常,RPA9 却正常的问题处理

    一.现象 RPA10.X 在一些极少数 win7/win10 环境中一运行就崩溃或无运行结果. 二.原因 出现上述现象已经确定是OPenGL 驱动兼容性造成的. 三.解决方法 方法一 只要把流程的管理 ...

  4. electron-vue在使用element-ui时部分组件无法显示问题

    原文连接: https://juejin.im/post/5d132629e51d45772a49ad71 问题描述 在使用electron开发桌面系统时,遇到部分element-ui组件在页面中无法 ...

  5. Hive学习笔记——metadata

    Hive结构体系 https://blog.csdn.net/zhoudaxia/article/details/8855937 可以在hive的jdbc接口中使用getMetaData方法来获取hi ...

  6. PLSQL无法连接64位Oracle数据库/Database下拉框为空的解决方法

    原创:https://blog.csdn.net/sdmanooo/article/details/14055077 今儿个重装了个系统,win7 64位.接着装了个64位的oracle11g,ora ...

  7. ros 源码安装

    版本lunar, 系统版本debian 9.8 参考: http://wiki.ros.org/lunar/Installation/Source 1. Installing bootstrap de ...

  8. 问题解决: 此文件来自其他计算机,可能被阻止以帮助保护该计算机/WORD在试图打开文件时遇到错误……

    最近,在打开下载的office文档(包括word.excel.ppt等)时候,总是无法直接打开,错误提示如下: 无论是邮件中的还是别的网站下载的,均提示该错误.后来搜索相关资料发现,修改其文件属性即可 ...

  9. ArcGIS Server 10.2忘记用户名密码的解决方案

    忘记了ArcGIS Server Manager的密码,可以采用以下方法进行重置. 1.找到ArcGIS Server的安装目录 D:\Program Files\ArcGIS\Server\tool ...

  10. 解决SQL语句在Dapper执行超时比Query慢的问题

    在语句结尾加上 Add OPTION (RECOMPILE) to the end https://stackoverflow.com/questions/10933366/sp-executesql ...