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. 007 Python程序语法元素分析

    目录 一.概述 二.程序的格式框架 2.1 代码高亮 2.2 缩进 2.3 注释 2.4 缩进.注释 三.命名与保留字 3.1 变量 3.2 命名 3.3 保留字 3.4 变量.命名.保留字 四.数据 ...

  2. Python(Head First)学习笔记:三

    3 文件与异常:调试.处理错误.迭代.改进.完善  处理错误:利用Python的异常处理机制来处理异常情况.  程序外部的数据:大多程序基本模型:首先输入数据,进行处理,然后存储.显示.打印或传输. ...

  3. HTML制作WORD表格

    效果图 table属性 align:让内容居中,取值为left.right.center border:设置表格的边框 cellspacing:单元格与单元格之间的距离 bgcolor:表格的背景色 ...

  4. 在JSP页面用EL表达式获取数据

    <h4>获取域对象中的值</h4><%    request.setAttribute("name", "射雕英雄传");     ...

  5. guava multimap介绍

    引用一篇别人的博客,理解理解 http://vipcowrie.iteye.com/blog/1517338

  6. 剖析nsq消息队列(二) 去中心化代码源码解析

    在上一篇帖子剖析nsq消息队列(一) 简介及去中心化实现原理中,我介绍了nsq的两种使用方式,一种是直接连接,还有一种是通过nslookup来实现去中心化的方式使用,并大概说了一下实现原理,没有什么难 ...

  7. 增删改查——Statement接口

    1.增加数据表中的元组 package pers.datebase.zsgc; import java.sql.Connection; import java.sql.DriverManager; i ...

  8. ASP.NET Core 3.0 使用gRPC

    一.简介 gRPC 是一个由Google开源的,跨语言的,高性能的远程过程调用(RPC)框架. gRPC使客户端和服务端应用程序可以透明地进行通信,并简化了连接系统的构建.它使用HTTP/2作为通信协 ...

  9. 大数据处理中的Lambda架构和Kappa架构

    首先我们来看一个典型的互联网大数据平台的架构,如下图所示: 在这张架构图中,大数据平台里面向用户的在线业务处理组件用褐色标示出来,这部分是属于互联网在线应用的部分,其他蓝色的部分属于大数据相关组件,使 ...

  10. Xshell无法连接Linux虚拟机问题

    遇到的情况是,在虚拟机下安装了Linux后,xshell无法连接远程的虚拟机. 我遇到的情况是虚拟机可以ping 主机,主机确ping不了虚拟机. 使用的VM设置了两个网卡,一个nat  一个host ...