Description
You're in the middle of writing your newspaper's end-of-year economics summary,
and you've decided that you want to show a number of charts to demonstrate how
different stocks have performed over the course of the last year. You've already
decided that you want to show the price of n different stocks, all at the same k
points of the year. A simple chart of one stock's price would draw lines between the points (0,
price0), (1, price1), ... , (k-1, pricek-1), where pricei is the price of the
stock at the ith point in time. In order to save space, you have invented the concept of an overlaid chart. An
overlaid chart is the combination of one or more simple charts, and shows the
prices of multiple stocks (simply drawing a line for each one). In order to avoid
confusion between the stocks shown in a chart, the lines in an overlaid chart may
not cross or touch. Given a list of n stocks' prices at each of k time points, determine the minimum
number of overlaid charts you need to show all of the stocks' prices.
Input

The first line of input will contain a single integer T, the number of test
cases. After this will follow T test cases on different lines, each of the form: n k
price0,0 price0,1 ... price0,k-1
price1,0 price1,1 ... price1,k-1
...
pricen-1,0 pricen-1,1 ... pricen-1,k-1 Where pricei,j is an integer, the price of the ith stock at time j.
Output

For each test case, a single line containing "Case #X: Y", where X is the number
of the test-case (1-indexed) and Y is the minimum number of overlaid charts
needed to show the prices of all of the stocks.
1 ≤ T ≤ 100
2 ≤ k ≤ 25
0 ≤ pricei,j ≤ 1000000
1 ≤ n ≤ 100
Sample Input

3
3 4
1 2 3 4
2 3 4 6
6 5 4 3
3 3
5 5 5
4 4 6
4 5 4
5 2
1 1
2 2
5 4
4 4
4 1
Sample Output

Case #1: 2
Case #2: 3
Case #3: 2

题解:

  这个题目首先,马上就可以知道那些股票可以放在一张纸上,那些不可以,那么就可以把可以放在一张纸上的点连边。

  那么,我们把股票看成一个点,一条路径看成一张纸,那么这个题目就转化成了最小路径覆盖的问题,用网络流或者二分图解决。

  想到这里,我发现我dinic忘了怎么打了,匈牙利也忘了,板子部分是找自己模板的,以后用dinic再打一遍吧。

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#define MAXN 1000
using namespace std;
int cost[MAXN][MAXN];
int flag[MAXN],can[MAXN][MAXN],too[MAXN];
int n,k,ans; void pre(){
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
for(int K=;k<=k;K++){
if((cost[i][K]>cost[j][K])&&(cost[i][K-]>cost[j][K-])) break;
if((cost[i][K]-cost[j][K])*(cost[i][K-]-cost[j][K-])<=) break;
if(K==k) can[i][j+n]=can[j+n][i]=;
}
} bool dfs(int now){
for(int i=n+;i<=n*;i++){
if(can[now][i]&&flag[i]==){
flag[i]=;
if(!too[i]||dfs(too[i])){
too[i]=now;return ;
}
}
}
return ;
} int main()
{
int t;cin>>t;
int Case=;
while(t--){
scanf("%d%d",&n,&k);
memset(cost,,sizeof(cost));
memset(can,,sizeof(can));
memset(too,,sizeof(too));
memset(flag,,sizeof(flag));ans=;
for(int i=;i<=n;i++)
for(int j=;j<=k;j++) scanf("%d",&cost[i][j]);
pre();
for(int i=;i<=n;i++){
for(int j=n+;j<=n*;j++) flag[j]=;
if(dfs(i)) ans++;
}
printf("Case #%d: %d\n",++Case,n-ans);
}
return ;
}

Stock Charts的更多相关文章

  1. 【简解】SP7556 Stock Charts

    题目大意 给出一个折线图,有N条线段,你想要把这些线段分成几个集合,使得每个集合中任意两条线段不相交. 求最少集合数. 分析 喵帕斯:以下提及的所有折线均指横坐标在\([1,k]\)里的折线段. 思考 ...

  2. Displaying Data in a Chart with ASP.NET Web Pages (Razor)

    This article explains how to use a chart to display data in an ASP.NET Web Pages (Razor) website by ...

  3. Soj题目分类

    -----------------------------最优化问题------------------------------------- ----------------------常规动态规划 ...

  4. HighCharts学习笔记(一)

    HighChars基本概述 Highcharts是一个纯js写成的插件库,很好的外观表现可以满足任何图标需求. 开始使用chart之前进行配置 全局配置: Highcharts.setOptions( ...

  5. Select the JavaScript graphing libraries you would like to compare

    Select the JavaScript graphing libraries you would like to compare:             Overview Summary Fus ...

  6. Python第三方库之openpyxl(11)

    Python第三方库之openpyxl(11) Stock Charts(股票图) 在工作表上按特定顺序排列的列或行中的数据可以在股票图表中绘制.正如其名称所暗示的,股票图表通常被用来说明股价的波动. ...

  7. Python3 读取和写入excel

    https://blog.csdn.net/weixin_43094965/article/details/82226263一.Excel 1.Excel文件三个对象 workbook: 工作簿,一个 ...

  8. Qt3升至Qt4需要注意的几件事项浅谈

    Qt3升至Qt4需要注意的几件事项浅谈 公司以前的项目是用Qt3写的,随着时间的推移慢慢显示出Qt3有多方面的限制,因此先公司决定用Qt4来改写这个项目,并为软件添加新功能,在此背景先编写此文章. 先 ...

  9. An Introduction to Stock Market Data Analysis with R (Part 1)

    Around September of 2016 I wrote two articles on using Python for accessing, visualizing, and evalua ...

随机推荐

  1. Docker搭建disconf环境,三部曲之三:细说搭建过程

    Docker下的disconf实战全文链接 <Docker搭建disconf环境,三部曲之一:极速搭建disconf>: <Docker搭建disconf环境,三部曲之二:本地快速构 ...

  2. Python默认参数

    在python函数中, 可以使用如下方式声明并初始化参数 def to_smash(total_candies, n_friends=3): """Return the ...

  3. volatile的工作原理

    volatile的特性: volatile可见性:对一个volatile的读,总可以看到对这个变量最终的写: volatile原子性:volatile对单个读/写具有原子性(32位Long.Doubl ...

  4. 在一个升序数组中添加最少的数字,使得从1--n之间所有的数都能用数组中几个数的和表示

    一个Java的笔试题上面遇到的题,当时没有做出来. 拆分: 序列升序 1--n所有的数都要能表示 用数组中数字的和表示 添加最少的数字 思路:这个要先从小的数开始表示,因为大的数可以用小数表示. 1- ...

  5. VMware Workstation Fixed Unable to connect to the MKS

    场景:早上开虚拟机时突然报这个错 解决办法如下: 以管理员的身份打开CMD,然后执行如下命令: net start vmx86 net start hcmon net start vmauthdser ...

  6. airflow使用SimpleHttpOperator实现http调用任务

    使用SimpleHttpOperator作为处理器的时候,会发现默认访问的地址www.google.com端口为443 例如下面这样定义的任务 task = SimpleHttpOperator( t ...

  7. 简单的Socket通信(简单的在线聊天)---winform

    注:本博客适合刚开始学习winform程序的初学者,大牛请绕道(跪求大牛指导文中不足) .....10w字废话自动省略,直接开始正题. 首先从最基本的建立winform开始(本项目用的Vs2017) ...

  8. 常用 JS 函数

    各种业务开发都离不开对数据的处理,然而遇到的很多数据都是不好处理的.这个时候就需要寻求搜索引擎的帮助.这种方法效率是非常低下的,而且根据作者的个性不能保证其对自己的口味.因此这篇文字包含了一份 JS ...

  9. Java第三次作业第四题

    4. [问题描述]读取一个文本文件in.txt,然后将这个文件的内容,反序写到另一个文件out.txt中. [输入形式]从文件in.txt中读信息. [输出形式]反序内容写入out.txt文件中. [ ...

  10. DirectX12 3D 游戏开发与实战第四章内容(下)

    Direct3D的初始化(下) 学习目标 了解Direct3D在3D编程中相对于硬件所扮演的角色 理解组件对象模型COM在Direct3D中的作用 掌握基础的图像学概念,例如2D图像的存储方式,页面翻 ...