题目链接:

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. IIS中报错弹出调试,系统日志-错误应用程序名称: w3wp.exe,版本: 8.5.9600.16384,时间戳: 0x5215df96(360主机卫士)

    偶遇一次特殊情况,在使用Web系统导入数据模版(excel)时,服务端IIS会报错并弹出调试框,然后整个网站都处于卡死的debug状态,如果点否不进行调试,则IIS会中断调试,Web系统继续执行,运行 ...

  2. Intellij IDEA 修改jsp 不能实时更新

    Intellij IDEA 修改jsp 不能实时更新 1. 首先,output要指定到项目的webapp下,这样应该就可以实时更新了 2. 我的问题是这样设置之后,也不可以,原来是可以的,重装系统之后 ...

  3. Groovy里面闭包中变量符号的查找与变量定义的限制

    class a { def v1 = "v1 in a" static def v2 = "v2 in a" def v4 = "v4 in a&qu ...

  4. selenium + python自动化测试(一)

    本篇随笔为散集.不多逼逼直接干 step 1:使用webdriver调用浏览器,webdriver支持的浏览器为Firefox(),IE(),Chrome(),不同的浏览器需要安装不同的驱动. 本文使 ...

  5. 2018-2019-2 20165221 【网络对抗技术】-- Exp6 信息搜集与漏洞扫描

    2018-2019-2 20165221 [网络对抗技术]-- Exp6 信息搜集与漏洞扫描 目录 1. 实践目标 2. 实践内容 3. 各种搜索技巧的应用 a. 搜索网址的目录结构 b.使用IP路由 ...

  6. oracle 表所占空间统计

    1.通过查询dba_segments Select owner,segment_name,sum(bytes)/1024/1024 as MB from dba_segments group by o ...

  7. dba_segements 没有所有的表的信息

    这是oracle11g新增的功能,假设一个一般的用户user新建了一张表user_table,这时切换到sys用户查看dba_segments 查看user_table的信息,发现dba_segmen ...

  8. Spring Cloud 2-Zuul 网关服务(六)

    Spring Cloud  Zuul  1.pom.xml 2.application.yml Application.java 1.pom.xml <!-- zuul 网关服务 --> ...

  9. 借助 LVS + Keepalived 实现负载均衡

    虽然现在云手段很高明了.但是这个lvs + keepalive 还是需要了解下的. 今天就整理了下lvs和keepalive的东西.做下总结留作以后怀念 在实际应用中,在Web服务器集群之前总会有一台 ...

  10. linux查找删除某天前的文件(转载)

    语句写法:find 对应目录 -mtime +天数 -name "文件名" -exec rm -rf {} \; 例1: 将/usr/local/backups目录下所有10天前带 ...