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

来源:互联网 发布:java tar打包代码 编辑:程序博客网 时间:2024/06/10 07:15

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
原创粉丝点击