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个数字, 然后两个人的数字进行比较; 数字小的那个人得到一个嘲讽 ...
随机推荐
- 将驱动编译进Linux内核
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- spark基础知识(1)
一.大数据架构 并发计算: 并行计算: 很少会说并发计算,一般都是说并行计算,但是并行计算用的是并发技术.并发更偏向于底层.并发通常指的是单机上的并发运行,通过多线程来实现.而并行计算的范围更广,他是 ...
- 【vue】渲染大量数据时性能优化
对应vue渲染大量数据时可以考虑下面几点: 1. 异步渲染组件:因为组件渲染太多,影响页面的渲染时间,所有可以延迟组件渲染,可以考虑v-if处理 2. 可以使用虚拟滚动的组件:参考使用这个插件 vue ...
- mysql命令行的导入导出sql,txt,excel(都在linux或windows命令行操作)(转自筑梦悠然)
原文链接https://blog.csdn.net/wuhuagu_wuhuaguo/article/details/73805962 Mysql导入导出sql,txt,excel 首先我们通过命令行 ...
- return *this和return this有什么区别?
return *this返回的是当前对象的克隆或者本身(若返回类型为A, 则是克隆, 若返回类型为A&, 则是本身 ). return this返回当前对象的地址(指向当前对象的指针). 转: ...
- 你循环的时候就可以给他们赋值了,那么就不用addClass,再根据类选择器处理,代码能一气呵成就别写成两段了
function onCopyButtonClick() { $(".index:checked").each(function () { $(] + "__WeekCo ...
- 手写代码 - java.util.List 相关
1-ArrayList 访问元素,不能使用ArrayList[0]形式!!!! 必须使用ArrayList.get(0);
- JSR-303 数据校验学习
一.JSR-303简介JSR-303 是 JAVA EE 6 中的一项子规范,叫做 Bean Validation,官方参考实现是Hibernate Validator. 此实现与 Hibernate ...
- 文件比较与同步工具——FreeFileSync
1. 基本介绍 FreeFileSync是一个用于文件同步的免费开源程序.FreeFileSync通过比较其内容,日期或文件大小上的一个或多个文件夹,然后根据用户定义的设置同步内容.除了支持本地文件系 ...
- 个人版整理APP测试流程
2016.1.5 我的笔记 一 .APP测试基本流程 1.1 测试周期 测试周期可按项目的开发周期来确定测试时间,一般测试时间为两三周(即15个工作日),根据项目情况以及版本质量可适当缩短或延长测试 ...