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. aarch64_l2

    libfreehand-devel-0.1.1-5.fc26.aarch64.rpm 2017-05-23 07:16 26K fedora Mirroring Project libfreehand ...

  2. Nodejs 发送邮件

    var nodemailer = require("nodemailer");var mailTitle='http://bemupa.forumieren.com:Best Mu ...

  3. a标签、img图片、iframe、表单元素、div

    1.<a href="http://www.baidu.com" target=''_blank">百度</a>  超链接标签 2.<img ...

  4. 【写在NOIP前】

    快NOIP了,感觉自己得总结一下吧. 1.要自信啊,相信自己啊,我明明还是有些实力的是吧. 哪怕之前被教练怎么怼,自己别放弃啊 一定要注意心态吧,考试的时候怎么都不能慌,你不会的题也不会有多少人会做的 ...

  5. bzoj 1607 Patting Heads 轻拍牛头

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1607 题解: 题目似乎出错,应为“同时拍打所有所持纸条上的数字能被此牛所持纸条上的数字整除 ...

  6. Django模型和ORM

    一.ORM ORM介绍 ORM概念 对象关系映射(Object Relational Mapping,简称ORM)模式是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术. 简单的说,ORM是 ...

  7. Unix IPC之pipe

    pipe创建函数: #include <unistd.h> /* Create a one-way communication channel (pipe). If successful, ...

  8. 根据后端传的时间前端js进行倒计时

    一.故事背景: 1. 今天公司有个项目需求 2. 在前端页面实现一个倒计时功能 3. 初步设想:后端根据需求规定一个未来的时间,前端根据当前时间进行计算 4. 然后将时间格式化,时分秒的格式 5. 时 ...

  9. MySQL学习笔记:生成时间维度表

    # ---- 对应时间戳怎么生成的? ---- /*TIME_CD TIME_CD1000000 000005000001 000005000002 000005000003 000005000004 ...

  10. 如何解决vuex因浏览器刷新数据消失,保持数据持久化问题?

    vuex的一个全局状态管理的插件,但是在浏览器刷新的时候,内存中的state会释放.通常的解决办法就是用本地存储的方式保存数据,然后再vuex初始化的时候再赋值给state,此过程有点麻烦.因此可以使 ...