题目链接:

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. web 框架

    一个实际的案例介绍Spring Boot + Vue 前后端分离 https://www.cnblogs.com/nele/p/7858581.html#_caption_7 https://www. ...

  2. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio

    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL ...

  3. Oracle DB 总结(SQL)

    --SQL结构查询语言 数据库定义语言(DDL)用于建立.删除和修改数据库对象 CREATE ALTER DROP TRUNCATE 数据库操纵语言(DML)用于改变数据库表中的数据 INSERT U ...

  4. react native navigationOptions中不能获取this

    static navigationOptions = ({ navigation, navigationOptions,screenProps }) => { const { params } ...

  5. 递归处理vue菜单数据

    结构不多说,bean的封装很简单,直接上核心代码吧,自己根据需要把不要的属性自己过滤掉: public List<MenuBo> getMenuByUserId(Long user_id, ...

  6. 一些C语言基础知识

    位运算 // 按位与&: 2 & 3 = 2: 010 & 011 = 010   两个1才为1 // 按位或|: 2 | 3 = 3: 010 | 011 = 011   只 ...

  7. 没有显示器如何SSH连接上树莓派

    1.在用读卡器烧录系统后先用Linux虚拟机连接上读卡器,修改 sudo gedit /etc/wpa_supplicant/wpa_supplicant.conf 加入 network={ ssid ...

  8. DBA_TABLES ALL_TABLES USER_TABLES

    DBA_TABLES >= ALL_TABLES >= USER_TABLES DBA_TABLES意为DBA拥有的或可以访问的所有的关系表. ALL_TABLES意为某一用户拥有的或可以 ...

  9. 百度杯”CTF比赛 2017 二月场 没错!就是文件包含漏洞。

    题目源码: 文件包含漏洞的话,看一下 你么可以使用php://input 伪协议,执行代码(参考了大佬WP)这里使用了POSTMAN, 目录下还有一个dle345aae.php文件,呢么用cat命令打 ...

  10. CentOS7各个版本镜像下载地址

    # CentOS7.6 下载地址 # CentOS-7-x86_64-DVD-1810.iso CentOS 7.6 DVD 版 4G http://mirrors.163.com/centos/7. ...