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. Linux系统下安装zookeeper教程

    环境: 1.VMware® Workstation 12 Pro 2.CentOS7 3.zookeeper-3.4.6 安装步骤 1.下载zookeeper 本文使用的zookeeper下载地址如下 ...

  2. vue 页面跳转传参

    页面之间的跳转传参,正常前端js里写 window.location.href="xxxxx?id=1" 就可以了: 但是vue不一样 需要操作的是路由history,需要用到 V ...

  3. CAS ABA问题

    java.util.concurrent包的最底层基础CAS技术,原理很简单. CAS有3个操作数,内存值V,旧的预期值A,要修改的新值B.当且仅当预期值A和内存值V相同时,将内存值V修改为B,否则什 ...

  4. SqlServer 2014还原数据库时提示:无法在已有的""上还原文件,请重新发出RESTORE语句,用WITH REPLACE来覆盖原先存在的文件

    场景 SQL Server 2014在还原数据库时提示: 无法在已有的""上还原文件,请重新发出RESTORE语句,用WITH REPLACE来覆盖原先存在的文件... 实现 在还 ...

  5. Set集合、List集合

    集合体系:Collection.Map接口 存储数量不等的多个对象,不能存储基本数据类型,如存储基本数据类型会自动装箱 ======================================== ...

  6. 02 (H5*) Vue第二天

    目录: 1:全局过滤器的使用 2:局部过滤器 3:自定义键盘码 4:自定义指令 5:自定义私有指令 6:Vue生命周期. 7:网络请求 1:全局过滤器的使用 Vue.filter("msgF ...

  7. Linux 修改 ls 时间显示格式

    [root@CentosTe tmp]# export TIME_STYLE='+%Y-%m-%d %H:%M:%S'[root@CentosTe tmp]# ll总计 24-rwx------ 1  ...

  8. 【linux】【jenkins】自动化部署一 安装jenkins及Jenkins工作目录迁移

    系统环境:Centos7 https://jenkins.io/zh/download/ 下载对应系统的jenkins 一.安装jdk8.0 jenkins安装需要jdk8or11,根据jenkins ...

  9. Selenium+python上传本地文件或者图片

    基于input标签的,有属性type = file: 首先定位到点击上传的元素(input)然后直接使用send_keys()将文件在本地的路径传进去 代码如下(例子来源于本页面上传图片和文件): f ...

  10. selenium-03-01截图函数

    UI自动化测试执行过程中,当遇到检查失败的情况,往往会发现打印的log并不能有效地帮助我们定位问题.我们需要失败时刻的屏幕截图来重现当时的失败场景,进而排查出错原因.   基于这种需求可以使用Sele ...