【简解】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相 ...
随机推荐
- 【LG2839】[国家集训队]middle
[LG2839][国家集训队]middle 题面 洛谷 题解 按照求中位数的套路,我们二分答案\(mid\),将大于等于\(mid\)的数设为\(1\),否则为\(-1\). 若一个区间和大于等于\( ...
- python变量d的说明
[变量] 什么是变量: 变:现实世界中的状态是会发生改变的. 量:记录现实世界中的状态,让计算机能够像人一样去识别世间万物 是变化的量 变量的组成: 变量名:变量名用来引用变量值,但凡需要用变量值,都 ...
- VxLAN原理
VxLAN 背景介绍: 从上个世纪虚拟化技术就被提出,但由于硬件技术达不到,而没能被重视,自本世纪初硬件制造技术越来越来强,导致很多单台物理机只跑一个应用或几个应用根本无法完全使用硬件的全部性能,导致 ...
- nginx 配置虚拟主机( 基于域名 )
一.创建网站目录及文件: [root@localhost data]# tree /data /data └── wwwroot ├── www..com │ └── index.html └── ...
- Golang 位向量
位图 位图(Bitmap)是通过一个 bit 来表示某个元素对应的值或者状态.它并不是什么新的数据结构.它的内容其实就是普通的字符串. 在redis中,我们可以通过 get/set 获取位图的内容,也 ...
- shell 命令行参数(基本)
命令行参数 $0 表示程序名.$1 至 \$9则是位置参数.$# 表示参数的个数.$* 将所有参数当做一个整体来引用$@ 把每个参数作为一个字符串返回,可以使用for循环来遍历$? 最近一个执行的命令 ...
- OpenFOAM——在钝板上分离的层流
本算例来自<ANSYS Fluid Dynamics Verification Manual>中的VMFL063: Separated Laminar Flow Over a Blunt ...
- zabbix 自动发现 监控 硬盘读写 disk io
直接 上配置: 1.配置文件 cat userparameter_harddisk.conf #discovery hard diskUserParameter=custom.vfs.discover ...
- 微信token介绍
这里的微信token 有以下三种 1.小程序的token (appid+appsecret=token) 2.一个是第三方平台token(comment_appid+comment_appsecre ...
- 【转载】 TensorFlow学习——tf.GPUOptions和tf.ConfigProto用法解析
原文地址: https://blog.csdn.net/c20081052/article/details/82345454 ------------------------------------- ...