Codeforces Round #603 (Div. 2) B. PIN Codes
链接:
https://codeforces.com/contest/1263/problem/B
题意:
A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0.
Polycarp has n (2≤n≤10) bank cards, the PIN code of the i-th card is pi.
Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all n codes would become different.
Formally, in one step, Polycarp picks i-th card (1≤i≤n), then in its PIN code pi selects one position (from 1 to 4), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different.
Polycarp quickly solved this problem. Can you solve it?
思路:
n最大是10, 直接暴力修改
代码:
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
string s[10];
map<string, int> Mp;
cin >> n;
for (int i = 0;i < n;i++)
cin >> s[i], Mp[s[i]]++;
int ans = 0;
for (int i = 0;i < n;i++)
{
if (Mp[s[i]] > 1)
{
ans++;
Mp[s[i]]--;
for (int j = 0;j < 10;j++)
{
s[i][0] = j+'0';
if (Mp[s[i]] == 0)
break;
}
Mp[s[i]]++;
}
}
cout << ans << endl;
for (int i = 0;i < n;i++)
cout << s[i] << endl;
}
return 0;
}
Codeforces Round #603 (Div. 2) B. PIN Codes的更多相关文章
- Codeforces Round #603 (Div. 2) B. PIN Codes 水题
B. PIN Codes A PIN code is a string that consists of exactly 4 digits. Examples of possible PIN code ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #603 (Div. 2)
传送门 感觉脑子还是转得太慢了QAQ,一些问题老是想得很慢... A. Sweet Problem 签到. Code /* * Author: heyuhhh * Created Time: 2019 ...
- Codeforces Round #603 (Div. 2) E. Editor 线段树
E. Editor The development of a text editor is a hard problem. You need to implement an extra module ...
- Codeforces Round #603 (Div. 2) E. Editor(线段树)
链接: https://codeforces.com/contest/1263/problem/E 题意: The development of a text editor is a hard pro ...
- Codeforces Round #603 (Div. 2) (题解)
A. Sweet Problem (找规律) 题目链接 大致思路: 有一点瞎猜的,首先排一个序, \(a_1>a_2>a_3\) ,发现如果 \(a_1>=a_2+a_3\) ,那么 ...
- Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集
D. Secret Passwords One unknown hacker wants to get the admin's password of AtForces testing system, ...
- Codeforces Round #603 (Div. 2) D. Secret Passwords(并查集)
链接: https://codeforces.com/contest/1263/problem/D 题意: One unknown hacker wants to get the admin's pa ...
- Codeforces Round #603 (Div. 2) C. Everyone is a Winner! (数学)
链接: https://codeforces.com/contest/1263/problem/C 题意: On the well-known testing system MathForces, a ...
随机推荐
- 【Appium + Python + WebviewH5】之微信小程序自动化测试
进行调试,打开X5: http://debugmm.qq.com/?forcex5=true http://debugx5.qq.com http://debugtbs.qq.com 一般前两个就可以 ...
- SpringBoot使用@ServerEndpoint无法依赖注入问题解决(WebSocket)
如上两图所示,在WebSocket中我想使用Redis.把自己编写的RedisUtil使用@Autowired自动注入到当前类. 在运行时,出现异常:java.lang.NullPointExcept ...
- 【题解】Luogu P5471 [NOI2019]弹跳
原题传送门 先考虑部分分做法: subtask1: 暴力\(O(nm)\)枚举,跑最短路 subtask2: 吧一行的点压到vector中并排序,二分查找每一个弹跳装置珂以到达的城市,跑最短路 sub ...
- 命令源码文件——Golang
源码文件又分为三种,即:命令源码文件.库源码文件和测试源码文件,它们都有着不同的用途和编写规则. 命令源码文件:1.独立程序的入口2.属于main包,包含无参数和无结果的main函数3.main函数执 ...
- Redis和数据库一致性
1.实时同步 对强一致要求比较高的,应采用实时同步方案,即查询缓存查询不到再从DB查询,保存到缓存: 更新缓存时,先更新数据库,再将缓存的设置过期(建议不要去更新缓存内容,直接设置缓存过期 ...
- Django model distinct 的使用方法
原文: 今天突然有人问起在 django 的 model 里面怎么用 distinct, 对于这种东西,我一向的观点是查看django 的在线文档.于是不加思索的根据在线文档给出了答案,但结果很让人沮 ...
- Python3字典与集合
一.Python3字典 字典是另一种可变容器模型,且可存储任意类型对象字典的每个键值(key=>value)对用冒号":"分割,每个键值对之间用逗号"," ...
- 【总结】web工作代码分类整理(持续更新)
文件.blob 文件下载失败,将Blob对象转换为Json,处理异常错误? 使用FileReader,核心代码: var reader = new FileReader() reader.onload ...
- JavaScript 变量与注释
一.变量 ECMAScript 的变量是松散类型的,所谓松散类型就是可以用来保存任何类型的数据. 换句话说,每个变量仅仅是一个用于保存值的占位符而已.定义变量时要使用 var 操作符(注意 var 是 ...
- 什么是MVC框架?
1.什么是mvc Model View Controller,是模型-视图-控制器的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码,将业务逻辑聚集到一个组件里,在改进和个性化 ...