CodeForces - 777B Game of Credit Cards 贪心
题目链接:
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 贪心的更多相关文章
- 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 ...
- Game of Credit Cards(贪心+思维)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- Codeforces 777B:Game of Credit Cards(贪心)
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- 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 ...
- 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 ...
- Codeforces 437C The Child and Toy(贪心)
题目连接:Codeforces 437C The Child and Toy 贪心,每条绳子都是须要割断的,那就先割断最大值相应的那部分周围的绳子. #include <iostream> ...
- Codeforces Round #546 (Div. 2) D 贪心 + 思维
https://codeforces.com/contest/1136/problem/D 贪心 + 思维 题意 你面前有一个队列,加上你有n个人(n<=3e5),有m(m<=个交换法则, ...
- Game of Credit Cards
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle betwe ...
- 【codeforces 777B】Game of Credit Cards
[题目链接]:http://codeforces.com/contest/777/problem/B [题意] 等价题意: 两个人都有n个数字, 然后两个人的数字进行比较; 数字小的那个人得到一个嘲讽 ...
随机推荐
- Windows API 调用示例
Ø 简介 本文主要记录 Windows API 的调用示例,因为这项技术并不常用,属于 C# 中比较孤僻或接触底层的技术,并不常用.但是有时候也可以借助他完成一些 C# 本身不能完成的功能,例如:通 ...
- flask+mod_wsgi+apache在windows上的布署
已经安装过python3.5 1.安装flask: pip install flask 2.安装apache: Apache是开源软件,针对windows环境,它不直接提供编译版本.可以在http:/ ...
- Java装箱的 " == " 的问题
装箱和拆箱 packagecom.xzj.Test; /* * @ author thisxzj * @ create 2019-02-25 10:56 */ publicclassBase{ ...
- Redis的安装与常用配置说明
1.redis安装步骤 1).下载,上传到Linux服务器,并解压 2).预编译(实际上是检查编译环境的过程) 进入目录: cd /opt/soft/redis-3.2.9/deps/jemall ...
- PLSQL Developer导入dmp文件,一闪而过
在导入数据的时候,一闪而过,也没有任何报错信息. 在环境变量里添加ORACLE_HOME=D:\app\product\11.2.0\dbhome_1就行,此路径是指oracle安装路径.我是用这种方 ...
- docker安装redis
查询镜像 docker search redis 拉取镜像 docker pull redis 启动容器 docker run --name redis -p 6379:6379 -d --resta ...
- 2018-2019-2 网络对抗技术 20165337 Exp3 免杀原理与实践
基础问题回答 (1)杀软是如何检测出恶意代码的? 基于特征码的检测:特征码就是一段数据.如果一个可执行文件(或其他运行的库.脚本等)包含特定的数据则被认为是恶意代码.AV软件厂商要做的就是尽量搜集最全 ...
- python numpy 间的的数据变算公式
import numpy as np a = np.arange(100) print(np.sum(a))#求和 print(np.mean(a))#平均值 print(np.max(a))#最大值 ...
- golang包管理工具glide安装
1:下载安装glide go get github.com/Masterminds/glide glide的源码以及exe文件在第一个gopath目录,如果不知道哪个是第一个gopath,echo一下 ...
- Mock.js简易教程,脱离后端独立开发,实现增删改查功能(转)
在我们的生产实际中,后端的接口往往是较晚才会出来,并且还要写接口文档,于是我们的前端的许多开发都要等到接口给我们才能进行,这样对于我们前端来说显得十分的被动,于是有没有可以制造假数据来模拟后端接口呢, ...