【codeforces 777B】Game of Credit Cards

【题目链接】:http://codeforces.com/contest/777/problem/B

【题意】
等价题意:
两个人都有n个数字,
然后两个人的数字进行比较;
数字小的那个人得到一个嘲讽;
问你如何搞
才能让莫里亚蒂得到的嘲讽最少;
莫里亚蒂得到的嘲讽最多;

【题解】

/*
    先考虑莫里亚蒂得到最小的;
    先把夏洛克的从小到大排序
    然后从小到大处理夏洛克的数字;
    对于夏洛克的每一个数字x
    尝试用一个>=x的但是最小的数来击败它.然后这个数打上标记;
    如果找不到大于等于它的数字,那么就结束;
    n-i+1就是莫里亚蒂得到的最小数目;
    因为夏洛克后面的数字会越来越大的;

    对于让夏洛克得到最多嘲讽;
    则只要把那个>=x改成>x的就好了;
    i-1就是夏洛克得到的最多嘲讽个数;
*/


【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%lld",&x)

typedef pair<int, int> pii;
typedef pair<LL, LL> pll;

const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 1e3+100;

int n;
int a[N], b[N];
char s[N];
bool bo[N];

int main()
{
    //freopen("F:\\rush.txt", "r", stdin);
    rei(n);
    scanf("%s", s + 1);
    rep1(i, 1, n)
        a[i] = s[i] - '0';
    scanf("%s", s + 1);
    rep1(i, 1, n)
        b[i] = s[i] - '0';
    sort(a + 1, a + 1 + n);
    int ans1 = 0;
    rep1(i, 1, n)
    {
        int mi = -1;
        rep1(j,1,n)
            if (!bo[j] && b[j] >= a[i])
            {
                if (mi == -1)
                    mi = j;
                else
                    if (b[j] < b[mi])
                        mi = j;
            }
        if (mi == -1)
        {
            ans1 = n - i + 1;
            break;
        }
        bo[mi] = true;
    }

    memset(bo, false, sizeof bo);
    int ans2 = n;
    rep1(i, 1, n)
    {
        int mi = -1;
        rep1(j, 1, n)
            if (!bo[j] && b[j] > a[i])
            {
                if (mi == -1)
                    mi = j;
                else
                    if (b[j] < b[mi])
                        mi = j;
            }
        if (mi == -1)
        {
            ans2 = i-1;
            break;
        }
        bo[mi] = true;
    }
    cout << ans1 << endl;
    cout << ans2 << endl;
    return 0;
}

转载于:https://www.cnblogs.com/AWCXV/p/7626595.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值