【简解】SP7556 Stock Charts
题目大意
给出一个折线图,有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的更多相关文章
- python ConfigParser、shutil、subprocess、ElementTree模块简解
ConfigParser 模块 一.ConfigParser简介ConfigParser 是用来读取配置文件的包.配置文件的格式如下:中括号“[ ]”内包含的为section.section 下面为类 ...
- Stock Charts
Description You're in the middle of writing your newspaper's end-of-year economics summary, and you' ...
- AC题目简解-数据结构
A - Japan POJ 3067 要两条路有交叉,(x1,y1)(x2,y2)那么需要满足:(x1-x2)*(y1-y2)<0判断出这是求逆序的问题 树状数组求逆序,先通过自定义的比较器实 ...
- UE4 RHI与Render模块简解
UE4中的RHI指的是Render hardware interface,作用像Ogre里的RenderSystem,针对Dx11,Dx12,Opengl等等平台抽象出相同的接口,我们能方便能使用相同 ...
- zabbix基本监控各指标简解
监控项目及使用模板 监控http和https: Template App HTTP Service Template App HTTPS Service 监控cpu,内存,网络等: Templ ...
- (转)FFMPEG解码H264拼帧简解
http://blog.csdn.net/ikevin/article/details/7649095 H264的I帧通常 0x00 0x00 0x00 0x01 0x67 开始,到下一个帧头开始之前 ...
- Spring ApplicationContext 简解
ApplicationContext是对BeanFactory的扩展,实现BeanFactory的所有功能,并添加了事件传播,国际化,资源文件处理等. configure locations:(C ...
- HTTP协议简解
1.什么是http协议 http协议: 浏览器客户端 与 服务器端 之间数据传输的规范 2.查看http协议的工具 1)使用火狐的firebug插件(右键->查看元素->网络) 2)使用 ...
- linux netstat 命令简解
Netstat 简介: Netstat是在内核中访问网络及相关信息的程序,它能提供TCP连接,TCP和UDP监听,进程内存管理的相关报告.常见参数-a (all)显示所有选项,默认不显示LISTEN相 ...
随机推荐
- ImportError: No module named 'typing'
k@ubuntu:~/Desktop/virtualenv$ python3 Python ( , ::) [GCC ] on linux Type "help", "c ...
- exit命令
exit命令用于退出当前shell,在shell脚本中可以终止当前脚本执行. 常用参数格式:exit n退出.设置退出码为n.(Cause the shell to exit with a statu ...
- 论文阅读:Single Image Dehazing via Conditional Generative Adversarial Network
Single Image Dehazing via Conditional Generative Adversarial Network Runde Li∗ Jinshan Pan∗ Zechao L ...
- Writeup:第五届上海市大学生网络安全大赛-Web
目录 Writeup:第五届上海市大学生网络安全大赛-Web 一.Decade 无参数函数RCE(./..) 二.Easysql 三.Babyt5 二次编码绕过strpos Description: ...
- 【Gamma阶段】第二次Scrum Meeting
冰多多团队-Gamma阶段第二次Scrum会议 工作情况 团队成员 已完成任务 待完成任务 卓培锦 修改可移动button以及button手感反馈优化 编辑器风格切换(夜间模式) 牛雅哲 语音输入sh ...
- Android: NDK中的Android.mk和Application.mk
1. 简介 Android.mk 可用来描述要编译的某个具体模块的相关信息.比如:指定编译该模块时所需要的源文件.编译该模块时要链接的库文件.该模块编译完成后生成的库的名字等等.Applicatio ...
- eclipse从git下载的maven项目需要转成maven才可是使用main方法启动
导入git项目: 选择导入git项目有会有两个选项:一个是从本地git仓库中导入项目,一个是从github远程仓库中导入项目 我们选择从远程仓库中导入项目: 然后选择本地存放该项目的git仓库 然后选 ...
- android 桌面图标添加数字角标
是否支持角标并不与手机厂商有关,而是你当前使用的launcher开发厂商有关. 方法实现: import android.app.Application; import android.app.Not ...
- mysql数据库架构设计与优化
mysql数据库架构设计与优化 2019-04-23 20:51:20 无畏D尘埃 阅读数 179 收藏 更多 分类专栏: MySQL 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA ...
- html css 浮层 侧边栏
2019-7-1 16:02:25 星期一 实现的效果是点击, 然后从左侧滑出, 再点击, 就滑进去 <!DOCTYPE HTML> <html lang="en" ...