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部署html代码到linux服务器,并进行域名解析

    本博客主要是说一下,如何将本地写好的html代码部署到linux服务器,并进行解析.下一篇博客将写一下,如何将html代码部署到阿里云服务器,并进行域名解析,以及在部署过程中遇到的问题和解决方法. 1 ...

  2. Myeclipse项目工程目录中各种Libraries的含义

    MyEclipse工程目录下一般会有以下几类Libraries,如图: 各种Libraries的含义如下: JRE System Library:Java SE 的常用库文件集合,构建任何Java项目 ...

  3. webpack中clean-webpack-plugin插件使用遇到的问题及解决方法

    webpack 会生成文件,然后将这些文件放置在 /dist 文件夹中,但是 webpack 无法追踪到哪些文件是实际在项目中用到的. 通常,在每次构建前清理 /dist 文件夹,是比较推荐的做法,因 ...

  4. 关于格林尼治时间(GMT)和DateTime相互转换的分享

    普及一下什么是格林尼治时间? 世界时UT即格林尼治 平太阳时间,是指格林尼治所在地的标准时间,也是表示地球自转速率的一种形式.以地球自转为基础的时间计量系统.地球自转的角度可用地方子午线相对于地球上的 ...

  5. Java第三次作业第三题

    3. 请补充下面的Socket通信程序内容: (1)Socket通信中的服务端程序:ChatServerSocket.java package naizi; import java.io.*; imp ...

  6. 13 (OC)* SDWebImage

    IOS SDWebImage实现原理详解   在之前我写过SDWebImage的使用方法,主要是用与获取网络图片,没有看过的朋友可以看看. 这篇文章将主要介绍SDWebImage的实现原理,主要针对于 ...

  7. JsonConvert 转DateTime类型为json 带T

    在调用接口的时候  将Model转换成json Datetime类型多了个T 用的是Newtonsoft.Json.dll 版本v4.5.0.0 代码:paramsjson = JsonConvert ...

  8. Spring Cloud 系列之 Spring Cloud Stream

    Spring Cloud Stream 是消息中间件组件,它集成了 kafka 和 rabbitmq .本篇文章以 Rabbit MQ 为消息中间件系统为基础,介绍 Spring Cloud Stre ...

  9. Vue学习之todolist功能开发

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Android 正 N 边形圆角头像的实现

    卖一下广告,欢迎大家关注我的微信公众号,扫一扫下方二维码或搜索微信号 stormjun94(徐公码字),即可关注. 目前专注于 Android 开发,主要分享 Android开发相关知识和一些相关的优 ...