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. C#基础——事件初步

    事件是C#语言的重要成员之一,初学者往往不能很好的去理解和运用事件,特别是自定义事件.在这里将以较简单的方式呈现事件最基本的用法. 1.事件的定义 给事件下定义是一个较困难的事,因为它体现的是对象与对 ...

  2. 增强学习Q-learning分析与演示(入门)

    一些说明.参阅 https://github.com/MorvanZhou/Reinforcement-learning-with-tensorflow/blob/master/contents/1_ ...

  3. git合并出现冲突

    git合并出现冲突:Your local changes to the following files would be overwritten by merge:Please, commit you ...

  4. redis持久化的两种方式RDB和AOF

    原文链接:http://www.cnblogs.com/tdws/p/5754706.html Redis的持久化过程中并不需要我们开发人员过多的参与,我们要做的是什么呢?除了深入了解RDB和AOF的 ...

  5. Net基础篇_学习笔记_第十天_方法_方法的调用问题

    在Main()函数中,调用Test()函数,我们管Main()函数称之为调用者,管Test()函数称之为被调用者.如果被调用者想要得到调用者的值:1).传递参数.2).使用静态字段来模拟全局变量.如果 ...

  6. 误删除系列一:linux的bin目录误删除后恢复操作

    感言:一失足成千古恨,一不小心就把/usr/bin下所有的命令都删除了,当你以为自己很熟练时,当你以为自己操作对时,可能就是失手的时候,还好这次只是一个测试环境....God 恢复过程:(以下是在vs ...

  7. 设置IntelliJ IDEA支持lambda表达式

    使用IntelliJ IDEA做为开发工具,对基于maven的java工程,如果要编写lambda表达式,先确保安装并使用了jdk1.8或者更高版本,然后再要做一些设置才能正常编译和执行,具体表现在m ...

  8. 【Jenkins持续集成(二)】Windows上安装Jenkins教程

    一.前言 Jenkins是一款开源 CI&CD 软件,用于自动化各种任务,包括构建.测试和部署软件. Jenkins 支持各种运行方式,可通过系统包.Docker 或者通过一个独立的 Java ...

  9. nginx如何配置负载均衡

    自己学习用 面试回答如下: 在nginx里面配置一个upstream,然后把相关的服务器ip都配置进去.然后采用轮询的方案,然后在nginx里面的配置项里,proxy-pass指向这个upstream ...

  10. hadoop集群zookeeper迁移

    1. zookeeper作用 ZooKeepr在Hadoop中的应用主要有: 1.1 HDFS中NameNode的HA和YARN中ResourceManager的HA. 1.2 存储RMStateSt ...