Codeforces Round #317 (Div. 2) (572A Arrays,572B Order Book)

1.572A Arrays

题目链接:
http://codeforces.com/problemset/problem/572/A

解题思路:

取第一个数列的第k个数,然后倒着取第二个数列的第m个数,比较即可。。。

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int a[100005];
int b[100005];

int main(){
    int l1,l2;
    while(~scanf("%d%d",&l1,&l2)){
        int k,m;
        scanf("%d%d",&k,&m);
        for(int i = 1; i <= l1; i++)
            scanf("%d",&a[i]);
        for(int i = 1; i <= l2; i++)
            scanf("%d",&b[i]);
        if(a[k] < b[l2-m+1])
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}



2.572B Order Book

题目链接:
http://codeforces.com/problemset/problem/572/B

解题思路:

英语不好的人,读题目起来真费解,特别是大半夜做题。。。那滋味。。。

题目大意:

给你n个做账记录(乱序给出),如果相同类且价格一样,则数量合并,取sell价格从小到大前s个,再取buy价格从大到小s个,最后先将sell价格从大到小输出,再将buy价格从大到小输出。。。

模拟即可。。。

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

const int maxn = 100005;
int buy[maxn],sell[maxn];
struct node{
    int p,q;
};
vector<node> vb,vs;

int main(){
    int n,s;
    while(~scanf("%d%d",&n,&s)){
        char op[5];
        int p,q;
        memset(buy,0,sizeof(buy));
        memset(sell,0,sizeof(sell));
        for(int i = 0; i < n; i++){
            scanf("%s%d%d",op,&p,&q);
            if(op[0] == 'B')
                buy[p] += q;
            else
                sell[p] += q;
        }
        vb.clear();
        vs.clear();
        for(int i = 0; i < maxn && vs.size() < s; i++)
            if(sell[i])
                vs.push_back(node{i,sell[i]});
        for(int i = maxn; i >= 0 && vb.size() < s; i--)
            if(buy[i])
                vb.push_back(node{i,buy[i]});

        for(int i = vs.size()-1; i >= 0; i--)
            printf("S %d %d\n", vs[i].p, vs[i].q);
        for (int i = 0; i < vb.size(); i++)
            printf("B %d %d\n", vb[i].p, vb[i].q);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值