Codeforces Edu Round 51 A-D
A. Vasya And Password
模拟题,将所缺的种类依次填入“出现次数$ >1 $”的位置,替换掉Ta即可。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 110;
char str[N];
int sum[3][N], n;
int inline get(char x){
if(x <= '9' && x >= '0') return 0;
else if(x >= 'a' && x <= 'z') return 1;
return 2;
}
void change(int pos, int x){
if(x == 0) str[pos] = '0';
else if(x == 1) str[pos] = 'a';
else str[pos] = 'A';
}
int main(){
int T; scanf("%d", &T);
while(T--){
scanf("%s", str + 1);
n = strlen(str + 1);
for(int i = 1; i <= n; i++){
for(int j = 0; j < 3; j++) sum[j][i] = sum[j][i - 1];
sum[get(str[i])][i]++;
}
int cnt = 0;
for(int i = 0; i < 3; i++) if(!sum[i][n]) cnt++;
if(cnt){
int tot = 0, l = 1, r = 1 + cnt - 1;
for(int i = l; i <= r; i++){
if(sum[get(str[i])][n] == 1) {
r++; continue;
}
while(sum[tot][n]) tot ++;
change(i, tot++);
}
}
printf("%s\n", str + 1);
}
return 0;
}
B. Relatively Prime Pairs
两个相邻的整数必然是互质的。
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
LL l, r, tot;
int main(){
cin >> l >> r;
if(l == r) puts("NO");
else{
puts("YES");
tot = (r - l + 1) >> 1;
for(LL i = l, j = 0; j < tot; j++, i+=2){
printf("%lld %lld\n", i, i + 1);
}
}
return 0;
}
C. Vasya and Multisets
模拟题,调了无数次,发现是自己没有理解题意。存在次数为\(1\)的数记为\(tot_1\),存在次数\(>2\)的数记为\(tot_2\)
\(tot_1\)个数不管划分到哪个集合,都会使那个集合的\(good number + 1\)。
这时候如果\(tot_1\)为奇数,则在\(tot_2\)中找一个数拆成\(1 + (x - 1)\)的模式分配即可。
#include <iostream>
#include <cstdio>
using namespace std;
const int N = 110;
int n, a[N], cnt[N], tot = 0, tot2 = 0, num = 0, st[N], cnt2[2][N];
bool vis[N];
char ans[N];
int main(){
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", a + i), cnt[a[i]]++;
for(int i = 1; i <= 100; i++){
if(cnt[i] == 1) tot++;
if(cnt[i] > 2) tot2++;
}
if((tot & 1) && (tot2)) tot++;
if(tot & 1) puts("NO");
else{
puts("YES"); tot >>= 1;
for(int i = 1; i <= n; i++){
if(cnt[a[i]] == 1){
if(num < tot)
ans[i] = 'A', num++, cnt2[0][a[i]]++;
else if(num < tot * 2)
ans[i] = 'B', num++, cnt2[1][a[i]]++;
}
}
for(int i = 1; i <= n; i++){
if(cnt[a[i]] != 1){
if(cnt[a[i]] == 2) ans[i] = 'A', cnt2[0][a[i]]++;
else if(vis[a[i]]) ans[i] = 'A' + st[a[i]], cnt2[st[a[i]]][a[i]]++;
else if(num < tot && (!vis[a[i]]))
ans[i] = 'A', vis[a[i]] = true, st[a[i]] = 1, num++, cnt2[0][a[i]]++;
else if(num < tot * 2 && (!vis[a[i]]))
ans[i] = 'B', st[a[i]] = 0, vis[a[i]] = true, num++, cnt2[1][a[i]]++;
else ans[i] = 'A', cnt2[0][a[i]]++;
}
}
for(int i = 1; i <= n; i++) printf("%c", ans[i]);
}
return 0;
}
D. Bicolorings
#include <iostream>
#include <cstdio>
using namespace std;
const int mod = 998244353, N = 1010;
typedef long long LL;
int n, k;
LL f[N][N << 1][4];
/* f[i][j][k] 代表前i列有j个联通快, type = k;
type = 0:
0
0
type = 1:
0
1
type = 2:
1
0
type = 3:
1
1
*/
int main(){
cin >> n >> k;
f[1][1][0] = f[1][2][1] = f[1][2][2] = f[1][1][3] = 1;
for(int i = 2; i <= n; i++){
for(int j = 1; j <= i * 2; j++){
(f[i][j][0] += f[i - 1][j][0] + f[i - 1][j][1] + f[i - 1][j][2] + f[i - 1][j - 1][3]) %= mod;
(f[i][j][1] += f[i - 1][j - 1][0] + f[i - 1][j][1] + (j >= 2 ? f[i - 1][j - 2][2] : 0) + f[i - 1][j - 1][3]) %= mod;
(f[i][j][2] += f[i - 1][j - 1][0] + (j >= 2 ? f[i - 1][j - 2][1] : 0) + f[i - 1][j][2] + f[i - 1][j - 1][3]) %= mod;
(f[i][j][3] += f[i - 1][j - 1][0] + f[i - 1][j][1] + f[i - 1][j][2] + f[i - 1][j][3]) %= mod;
}
}
LL res = 0;
for(int i = 0; i < 4; i++) (res += f[n][k][i]) %= mod;
cout << res;
return 0;
}
Codeforces Edu Round 51 A-D的更多相关文章
- Codeforces Beta Round #51 C. Pie or die 博弈论找规律 有趣的题~
C. Pie or die Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem/ ...
- Codeforces Beta Round #51 B. Smallest number dfs
B. Smallest number Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/pro ...
- Codeforces Beta Round #51 A. Flea travel 水题
A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...
- Codeforces Beta Round #51 D. Beautiful numbers 数位dp
D. Beautiful numbers Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/p ...
- Codeforces Beta Round #51 D. Beautiful numbers(数位dp)
题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...
- Codeforces Beta Round #51 D. Beautiful numbers
D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...
- codeforces 55d//Beautiful numbers// Codeforces Beta Round #51
题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记 ...
- Codeforces Beta Round #80 (Div. 2 Only)【ABCD】
Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...
- Codeforces Beta Round #62 题解【ABCD】
Codeforces Beta Round #62 A Irrational problem 题意 f(x) = x mod p1 mod p2 mod p3 mod p4 问你[a,b]中有多少个数 ...
随机推荐
- mysql之分区表
1.分区表概述: 1.分区表的主要意义在于,对于表结构进行划分,不同的数据进入不同的分区中,以便于在查询过程中,只查找指定分区的数据,减少数据库扫描的数据量. 2.虽然从逻辑上看分区表是一张表,但是底 ...
- Spark3.0.1各种集群模式搭建
对于spark前来围观的小伙伴应该都有所了解,也是现在比较流行的计算框架,基本上是有点规模的公司标配,所以如果有时间也可以补一下短板. 简单来说Spark作为准实时大数据计算引擎,Spark的运行需要 ...
- Nginx实例
一.反向代理 反向代理实例一 1.实现效果 打开浏览器,在浏览器地址栏输入地址www.pluto.com,跳转到 liunx 系统 tomcat 主页面中 2.准备工作 [1].安装tomcat [r ...
- centos 6 系统下同步本地时间
1.date显示系统时间 [root@oldboy ~]# dateTue Mar 31 22:45:55 CST 2020 #CST是指是指某中标准时间 非东八区时间 更改时间的三种方法 1.c ...
- SMBv3远程代码执行漏洞复现(CVE-2020-0796)
漏洞基本信息 服务器消息块(SMB),是一个网络通信协议,用于提供共享访问到文件,打印机和串行端口的节点之间的网络上.它还提供了经过身份验证的进程间通信机制.SMB的大多数用法涉及运行Microsof ...
- webug第三关:你看到了什么?
第三关:你看到了什么? 右键源码 扫描到test目录
- Ubuntu16.04安装搜狗输入法报错:dkpg:处理归档sogoupinyin.deb(--install)时出错,安装sogoupinyin将破坏fcitx-ui-qimpanel
系统:ubuntu16.04 事件:安装搜狗拼音时报错 报错信息(ubuntu语言是英文的报错信息): dpkg: regarding sogoupinyin_2.3.2.07_amd64-831.d ...
- CleanMyMac X“断网激活”真的能激活软件吗?
CleanMyMac X帮助Mac系统进行垃圾清理,清除多余的缓存.应用程序等,在提高工作效率上起了很大的作用.但是随着对软件的需求不断增加,很多人开始研究通过捷径破解正版软件,但是是否能成功呢?今天 ...
- VMW14.x虚拟机安装Mac10.13系统教程
之前虚拟机安装Mac经常出问题,所以这次又重新安装Mac,为了加深映像和之后回忆方便,特写下此次安装教程. 一 工具的准备: 首先准备教程的软件和包 1,虚拟机VMW 下载地址:https:// ...
- LeetCode 018 4Sum
题目描述:4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c ...