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. [NOI2014]购票 「树上斜率优化」

    首先易得方程,且经过变换有 $$\begin{aligned} f_i &= \min\limits_{dist_i - lim_i \le dist_j} \{f_j + (dist_i - ...

  2. TCP协议端口状态说明:CLOSE-WAIT、TIME-WAIT 、LISTENING、SYN_SENT、ESTABLISHED、LAST-ACK ...

    了解TCP协议端口的连接状态,对排除和定位网络或系统故障会有很大帮助,因此了解一下是有必要的: 一.LISTENING  提供某种服务,侦听远方TCP端口的连接请求,当提供的服务没有被连接时,处于LI ...

  3. 【Android开发日记】之入门篇(六)——Android四大组件之Broadcast Receiver

    广播接受者是作为系统的监听者存在着的,它可以监听系统或系统中其他应用发生的事件来做出响应.如设备开机时,应用要检查数据的变化状况,此时就可以通过广播来把消息通知给用户.又如网络状态改变时,电量变化时都 ...

  4. matlab随笔(二)

    circshift 两种形式 :第一种Y = circshift(A,K)就不用说了,将A中的元素向右移动K个位置. 需要注意的是第二种形式:Y = circshift(A,K,dim),这种形式不好 ...

  5. Spring框架的基本使用(IOC部分)

    Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架. Spring的好处 1.方便解耦,简化开发: Spring就是一个大工厂,专门负责生成Bean,可以将所有对象创建和依赖关 ...

  6. Luogu P3384 【【模板】树链剖分】

    转载请注明出处,部分内容引自banananana大神的博客 ~~别说你不知道什么是树~~╮(─▽─)╭(帮你百度一下) 先来回顾两个问题:1,将树从x到y结点最短路径上所有节点的值都加上z 这也是个模 ...

  7. Linux学习笔记:ls和ll命令

    list显示当前目录中的文件名字,不加参数时显示除隐藏文件外的所有文件及目录的名字. ll 等同于 ls -l-r 对目录反向排序(按字母)-t 以时间排序-u 以文件上次被访问的时间排序-x 按列输 ...

  8. Effective STL 学习笔记 Item 18: 慎用 vector<bool>

    vector<bool> 看起来像是一个存放布尔变量的容器,但是其实本身其实并不是一个容器,它里面存放的对象也不是布尔变量,这一点在 GCC 源码中 vector<bool> ...

  9. pytest mark中的skip,skipif, xfail

    这些测试的过滤,或是对返回值的二重判断, 可以让测试过程更精准,测试结果更可控, 并可以更高层的应用测试脚本来保持批量化执行. import pytest import tasks from task ...

  10. jsp页面中注释 <!-- --> 和<%-- --%> 的区别

    jsp页面中注释 <!-- --> 和<%-- --%> 的区别 原创 2016年09月01日 17:55:44 标签: jsp注释 5605 今天发现一个问题:在jsp代码中 ...