• hdu 4163 Stock Prices 水


    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    #define pi (4*atan(1.0))
    #define eps 1e-14
    const int N=1e6+100,M=4e6+10,inf=1e9+10,mod=1e9+7;
    const ll INF=1e18+10;
    struct is
    {
        int x;
        int pos;
    }a[N];
    int cmp1(is a,is b)
    {
        if(a.x!=b.x)
        return a.x<b.x;
        return a.pos<b.pos;
    }
    int cmp2(is a,is b)
    {
        if(a.x!=b.x)
        return a.x>b.x;
        return a.pos>b.pos;
    }
    int cmp3(is a,is b)
    {
        return a.pos>b.pos;
    }
    int cmp4(is a,is b)
    {
        return a.pos<b.pos;
    }
    int main()
    {
        int n,k1,k2,cas=1;
        while(~scanf("%d%d%d",&n,&k1,&k2))
        {
            if(n==0&&k1==0&&k2==0)
                break;
            for(int i=1;i<=n;i++)
                scanf("%d",&a[i].x),a[i].pos=i;
            sort(a+1,a+n+1,cmp1);
            sort(a+1,a+k1+1,cmp4);
            printf("Case %d
    ",cas++);
            for(int i=1;i<=k1;i++)
                printf("%d%c",a[i].pos,(i!=k1)?' ':'
    ');
            sort(a+1,a+n+1,cmp2);
            sort(a+1,a+k2+1,cmp3);
            for(int i=1;i<=k2;i++)
                printf("%d%c",a[i].pos,(i!=k2)?' ':'
    ');
        }
        return 0;
    }

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)


    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
     
    Source
  • 相关阅读:
    swift中数组和字典得使用,及循环得使用方法(xcode6版本上所写代码)
    ScrollView各属性,及代理方法汇总
    贝塞尔曲线
    iOS基础教程-collectionView的应用
    iOS中,使用block传值简单应用
    ES6~Promise的原理及使用一(copy自: https://www.cnblogs.com/lvdabao/p/jquery-deferred.html)
    react~setState的运行机制
    react ~4.组件table的使用及表格分页处理
    react ~3.动态无限层级顶部菜单和左边菜单设计制作
    react ~2.登陆页面验证码的获取传递与刷新
  • 原文地址:https://www.cnblogs.com/jhz033/p/5953920.html
Copyright © 2020-2023  润新知