题目链接:

http://codeforces.com/problemset/problem/777/B

题目大意:

A, B玩游戏,每人一串数字,数字不大于1000,要求每人从第一位开始报出数字,并且比较,如果等于则没事,A>B则B被打一下,反之A被打一下,A很老实不会耍计谋,老老实实从第一个开始报,但是B很狡猾,会改变数字的顺序。问2个次数,一个是B最小被打的次数,二是A最多被打的次数。

思路:

贪心,模拟一下就行了。这里用到了cmp的技巧,直接用字符比较,这样就省去了转换为字符串的步骤。

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std;
const int MX = +;
char a[MX], b[MX]; bool cmp(char a, char b)
{
return a < b;
} int main()
{
int n;
int cnt1 = ;
int cnt2 = ;
scanf("%d", &n);
scanf("%s", a); scanf("%s", b);
sort(a, a+n, cmp); sort(b, b+n, cmp);
for(int i = , j = ; j < n; ++j) //从头开始遍历比较完,找到B被打的最小次数
{
if(a[i] <= b[j]) i++; //这里从a,b最小值开始一直找到a > b,其中一起不断增大这样能找到b最少被打的次数
else cnt1++;
}
for(int i = n-, j = n-; i >= ; --i) //从尾开始遍历,从a, b的最大值开始,其中a不断减小,b遇到合适的再减小,这样能找到A最多被打的次数,
{
if(b[j] > a[i])
{
cnt2++;
j--;
}
}
printf("%d\n%d\n", cnt1, cnt2);
}

如有疑问,欢迎评论指出!

CodeForces - 777B Game of Credit Cards 贪心的更多相关文章

  1. Codeforces 777B Game of Credit Cards

    B. Game of Credit Cards time limit per test:2 seconds memory limit per test:256 megabytes input:stan ...

  2. Game of Credit Cards(贪心+思维)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  3. Codeforces 777B:Game of Credit Cards(贪心)

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  4. code force 401B. Game of Credit Cards

    B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  5. Codeforces777B Game of Credit Cards 2017-05-04 17:19 29人阅读 评论(0) 收藏

    B. Game of Credit Cards time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. Codeforces 437C The Child and Toy(贪心)

    题目连接:Codeforces 437C  The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...

  7. Codeforces Round #546 (Div. 2) D 贪心 + 思维

    https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...

  8. Game of Credit Cards

    After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...

  9. 【codeforces 777B】Game of Credit Cards

    [题目链接]:http://codeforces.com/contest/777/problem/B [题意] 等价题意: 两个人都有n个数字, 然后两个人的数字进行比较; 数字小的那个人得到一个嘲讽 ...

随机推荐

  1. python try exception finally记录

    try exception finally中,finally下的语句块始终会执行 测试finally代码 def test_try_exception(a, b): '''测试异常捕获语句''' re ...

  2. laravel-mix的安装

    Laravel-mix的安装 Laravel Mix 是一款前端任务自动化管理工具,使用了工作流的模式对制定好的任务依次执行.Mix 提供了简洁流畅的 API,让你能够为你的 Laravel 应用定义 ...

  3. ssm多数据源配置

    1.在.properties配置文件中 添加第二个数据源信息(type2,driver2, url2,username2,pawwword2) 2.修改spring-context.xml(src/m ...

  4. java Socket实例

    可以实现客户端与服务端双向通信,支持多客户端连接,客户端断开连接,服务端不会出现异常 服务端代码: package com.thinkgem.jeesite.modules.socketTest.de ...

  5. 产品研发不等待 i.MX6Q全新推出增强版本 官方店铺下单双重优惠

    迅为全新推出PLUS版本的i.MX6Q方案,版本介绍:它是NXP公司全新推出的i.MX6Q增强版新品,显著增强了图形和存储器性能,面向较高图形性能的先进消费电子.汽车和工业多媒体应用的多核平台.

  6. npx 是什么?

    参考链接:https://www.jianshu.com/p/cee806439865

  7. encode与decode

    import torch from torch import nn import numpy as np import matplotlib.pyplot as plt import torch.ut ...

  8. 团队Github实战训练

    班级:软件工程1916|W 作业:团队Github实战训练 团队名称:SkyReach Github地址:Github地址 贡献比例表 队员学号 队员姓名 此次活动任务 贡献比例 221600106 ...

  9. Numpy 多维数组简介

     NumPy是一个功能强大的Python库,主要用于对多维数组执行计算.NumPy这个词来源于两个单词-- Numerical和Python.NumPy提供了大量的库函数和操作,可以帮助程序员轻松地 ...

  10. Git(1):版本库+工作区+暂存区

    参考博客:https://blog.csdn.net/qq_27825451/article/details/69396866