Stock Prices

Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 987    Accepted Submission(s): 397

Problem Description
Buy
low, sell high. That is what one should do to make profit in the stock
market (we will ignore short selling here). Of course, no one can tell
the price of a stock in the future, so it is difficult to know exactly
when to buy and sell and how much profit one can make by repeatedly
buying and selling a stock.

But if you do have the history of
price of a stock for the last n days, it is certainly possible to
determine the maximum profit that could have been made. Instead, we are
interested in finding the k1 lowest prices and k2 highest prices in the
history.

 
Input
The
input consists of a number of cases. The first line of each case starts
with positive integers n, k1, and k2 on a line (n <= 1,000,000, k1 +
k2 <= n, k1, k2 <= 100). The next line contains integers giving
the prices of a stock in the last n days: the i-th integer (1 <= i
<= n) gives the stock price on day i. The stock prices are
non-negative. The input is terminated by n = k1 = k2 = 0, and that case
should not be processed.
 
Output
For
each case, produce three lines of output. The first line contains the
case number (starting from 1) on one line. The second line specifies the
days on which the k1 lowest stock prices occur. The days are sorted in
ascending order. The third line specifies the days on which the k2
highest stock prices occur, and the days sorted in descending order. The
entries in each list should be separated by a single space. If there
are multiple correct lists for the lowest prices, choose the
lexicographically smallest list. If there are multiple correct lists for
the highest prices, choose the lexicographically largest list.
 
Sample Input
10 3 2
1 2 3 4 5 6 7 8 9 10
10 3 2
10 9 8 7 6 5 4 3 2 1
0 0 0
 
Sample Output
Case 1
1 2 3
10 9
Case 2
8 9 10
2 1
 
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 1000001
const int inf=0x7fffffff; //无限大
struct node
{
int x;
int y;
};
node a[maxn];
node b[maxn];
bool cmp(node c,node d)
{
if(c.x==d.x)
return c.y<d.y;
return c.x<d.x;
}
bool cmp1(node c,node d)
{
return c.y>d.y;
}
bool cmp2(node c,node d)
{
return c.y<d.y;
}
int main()
{
int n,k1,k2;
int cas=;
while(scanf("%d%d%d",&n,&k1,&k2)!=EOF)
{
if(n==)
break;
for(int i=;i<n;i++)
{
scanf("%d",&a[i].x);
a[i].y=i+;
}
sort(a,a+n,cmp);
sort(a,a+k1,cmp2);
sort(a+n-k2,a+n,cmp1);
printf("Case %d\n",cas++);
int first=;
for(int i=;i<k1;i++)
{
if(first)
{
printf("%d",a[i].y);
first=;
}
else
printf(" %d",a[i].y);
}
printf("\n");
first=;
for(int i=n-k2;i<n;i++)
{
if(first)
{
printf("%d",a[i].y);
first=;
}
else
printf(" %d",a[i].y);
}
printf("\n");
}
return ;
}

hdu 4163 Stock Prices 花式排序的更多相关文章

  1. hdu 4163 Stock Prices 水

    #include<bits/stdc++.h> using namespace std; #define ll long long #define pi (4*atan(1.0)) #de ...

  2. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  3. hdu 5098 双队列拓扑排序

    http://acm.hdu.edu.cn/showproblem.php?pid=5098 软件在安装之后需要重启才能发挥作用,现在给你一堆软件(有的需要重启有的不需要)以及安装这个软件之前需要哪些 ...

  4. HDU 5811 Colosseo(拓扑排序+单调DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5811 [题目大意] 给出 一张单向图,现在将其划分成了两个部分,问划分之后的点是否分别满足按照一定 ...

  5. HDU 5738 Eureka(极角排序)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5738 [题目大意] 给出平面中一些点,在同一直线的点可以划分为一个集合,问可以组成多少包含元素不少 ...

  6. (hdu) 4857 逃生 (拓扑排序+优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4857 Problem Description 糟糕的事情发生啦,现在大家都忙着逃命.但是逃命的通道很窄 ...

  7. HDU 2647 Reward(拓扑排序+判断环+分层)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 题目大意:要给n个人发工资,告诉你m个关系,给出m行每行a b,表示b的工资小于a的工资,最低工 ...

  8. hdu 5188 zhx and contest [ 排序 + 背包 ]

    传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  9. HDU 5695 Gym Class 拓扑排序

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5695 题解: 求出字典序最大的拓扑序.然后把求好的数列翻转过来就是满足条件的数列,然后模拟求一下va ...

随机推荐

  1. VC++ 编译libcurl 支持SSL,GZIP

    由于网上下载的 libcurl 不支持 gzip,只好自己动手编译,期间走了很多弯路,下面是最终成功的记录. 我所使用的环境 Visual Studio 2010 . Windows 7 64 bit ...

  2. HTTP之二 http 301 和 302的区别

    1.什么是301转向?什么是301重定向? 301转向(或叫301重定向,301跳转)是当用户或搜索引擎向网站服务器发出浏览请求时,服务器返回的HTTP数据流中头信息(header)中的状态码的一种, ...

  3. 利用CSS函数calc(...)实现Web页面左右布局

    前言 因为自己的网站需要,想要做一个左右布局的页面: 左边是导航菜单之类的东西.右边是文档内容(因为最近看的一些软件的文档页面都是这么布局的): 左边固定宽度——300像素.右边使用剩余的宽度: 左边 ...

  4. 用monit监控系统关键进程

    原地址: https://feilong.me/2011/02/monitor-core-processes-with-monit monit是一款功能强大的系统状态.进程.文件.目录和设备的监控软件 ...

  5. URL的井号

    2010年9月,twitter改版. 一个显著变化,就是URL加入了"#!"符号.比如,改版前的用户主页网址为 http://twitter.com/username 改版后,就变 ...

  6. css同时满足两个类名才有效果的写法

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  7. LeetCode446. Arithmetic Slices II - Subsequence

    A sequence of numbers is called arithmetic if it consists of at least three elements and if the diff ...

  8. 浅谈C、C++及其区别、兼容与不兼容

    一.闲说C C语言之所以命名为C,是因为C语言源自Ken Thompson发明的B语言,而 B语言则源自BCPL语言. 1967年,剑桥大学的Martin Richards对CPL语言进行了简化,于是 ...

  9. Storm(一)Storm的简介与相关概念

    一.Storm的简介 官网地址:http://storm.apache.org/ Storm是一个免费开源.分布式.高容错的实时计算系统.Storm令持续不断的流计算变得容易,弥补了Hadoop批处理 ...

  10. JSON解析代码

    /** * 解析有数据头的纯数组 */ private void parseHaveHeaderJArray() { //拿到本地JSON 并转成String String strByJson = J ...