HDU 4163-Stock prices Fancy Sort

Source: Internet
Author: User
Tags cas stock prices

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 Descriptionbuy low, sell high. That's what one should does to make profit on the stock market (we'll ignore short selling here). Of course, no one can tell the price of a stock on the future, so it was 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 has the history of price of a stock for the last n days, it's certainly possible to determine the maximum Profit that could has been made. Instead, we is interested in finding the K1 lowest prices and k2 highest prices in the history.

Inputthe input consists of a number of cases. The first line of all 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 on the last n days:the i-th integer (1 <= i <= N) give s the stock price on day I. The stock prices is non-negative. The input is terminated by n = K1 = K2 = 0, and this case should not be processed.

Outputfor 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 "the" on which the K1 lowest the stock prices occur. The days is sorted in ascending order. The third line specifies the "the" on which the K2 highest the stock prices occur, and the "days" sorted in descending order. The entries in each list should is separated by a single space. If There is multiple correct lists for the lowest prices, choose the lexicographically smallest list. If There is multiple correct lists for the highest prices, choose the lexicographically largest list.

Sample Input10 3 21 2 3 4 5 6 7 8 9 1010 3 210 9 8 7 6 5 4 3 2 10 0 0

Sample outputcase 2 310 9Case 28 9 102 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>typedefLong Longll;using namespacestd;//freopen ("d.in", "R", stdin);//freopen ("D.out", "w", stdout);#defineSspeed ios_base::sync_with_stdio (0); Cin.tie (0)#defineMAXN 1000001Const intinf=0x7fffffff;//infinitely Largestructnode{intx; inty;}; Node A[maxn];node B[MAXN];BOOLCMP (node C,node d) {if(c.x==d.x)returnc.y<D.y; returnc.x<d.x;}BOOLCMP1 (node C,node d) {returnC.y>D.y;}BOOLCMP2 (node C,node d) {returnc.y<D.y;}intMain () {intN,k1,k2; intcas=1;  while(SCANF ("%d%d%d", &AMP;N,&AMP;K1,&AMP;K2)! =EOF) {        if(n==0)             Break;  for(intI=0; i<n;i++) {scanf ("%d",&a[i].x); A[i].y=i+1; } sort (A,a+n,cmp); Sort (A,a+K1,CMP2); Sort (a+n-k2,a+N,CMP1); printf ("Case %d\n", cas++); intfirst=1;  for(intI=0; i<k1;i++)        {            if(first) {printf ("%d", A[I].Y); First=0; }            Elseprintf ("%d", A[I].Y); } printf ("\ n"); First=1;  for(inti=n-k2;i<n;i++)        {            if(first) {printf ("%d", A[I].Y); First=0; }            Elseprintf ("%d", A[I].Y); } printf ("\ n"); }    return 0;}

HDU 4163-Stock prices Fancy Sort

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.