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的更多相关文章

  1. 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/ ...

  2. 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 ...

  3. Codeforces Beta Round #51 A. Flea travel 水题

    A. Flea travel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55/problem ...

  4. 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 ...

  5. Codeforces Beta Round #51 D. Beautiful numbers(数位dp)

    题目链接:https://codeforces.com/contest/55/problem/D 题目大意:给你一段区间[l,r],要求这段区间中可以整除自己每一位(除0意外)上的数字的整数个数,例如 ...

  6. Codeforces Beta Round #51 D. Beautiful numbers

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  7. codeforces 55d//Beautiful numbers// Codeforces Beta Round #51

    题意:一个数能整除它所有的位上的数字(除了0),统计这样数的个数. 注意离散化,为了速度更快需存入数组查找. 不要每次memset,记录下已有的长度下符合条件的个数. 数位dp肯定是从高位到低位. 记 ...

  8. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  9. 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]中有多少个数 ...

随机推荐

  1. Redis在springboot项目的使用

    一.在pom.xml配置redis依赖 <!-- redis客户端代码 --> <dependency> <groupId>org.springframework. ...

  2. bluestore的osd自启动

    前言 自启动相关的文章很多,有分析的很详细的文章,这里就不做赘述,本篇讲述的是什么情况下用,怎么用的问题 使用场景 一台机器的系统盘坏了,需要重装系统,相关的一些信息没有了,但是上面的数据盘还是在的, ...

  3. SpringAop切面实现日志记录

    SpringAop切面实现日志记录代码实现:https://www.cnblogs.com/wenjunwei/p/9639909.html 问题记录 1.signature.getMethod(). ...

  4. Rest语法,传入多个参数

    Rest语法,传入多个参数 js调用函数时可以传入任意数量的参数,而不报错.如果传入的参数没有用到,那么传入多余的参数没有任何用处,那不是瞎子点灯白费蜡嘛.为了充分利用传入的每一个参数,我们可以采用R ...

  5. 对于this和当前线程的一些理解

    在学习这个InheritableThreadLocal类的时候,我对于有个地方一直没有理解,我发现了盲点. 1 private void init(ThreadGroup g, Runnable ta ...

  6. QBXT 提高组储备营 2020.夏 游记

    DAY 1 是第一天呐!老师好强!讲得好仔细!连我都全懂了![doge] 突然对后面几天充满了期待-- 复习内容:二分,排序,贪心,搜索(好评) 新知识:Huffman树及Huffman编码,对拍,二 ...

  7. Codeforces Round #668 (Div. 2) D. Tree Tag 题解(博弈)

    题目链接 题目大意 给你一颗树,Alice在a点,Bob在b点,Alice最多走da步,Bob最多走db步,两人轮流走路.要你判断经过无数次追赶后,Alice是否可以追上Bob,两人进行的都是最优策略 ...

  8. 在运行tsc编译.ts文件时,“因为在此系统上禁止运行脚本” 怎么解决?

    tsc : 无法加载文件 C:\Users\Administrator\AppData\Roaming\npm\tsc.ps1,因为在此系统上禁止运行脚本.有关详细信息,请参阅 https:/go.m ...

  9. 软件工程与UML第三次作业

    博客班级 软件工程与UML2班 作业要求 本次作业要求 作业目标 <给至少5名同学提他的代码issue并用博客记录;根据收到的issue修改自己的代码> 作业源代码 我的码云仓库 学号 & ...

  10. 冲刺随笔——Day_Six

    这个作业属于哪个课程 软件工程 (福州大学至诚学院 - 计算机工程系) 这个作业要求在哪里 团队作业第五次--Alpha冲刺 这个作业的目标 团队进行Alpha冲刺 作业正文 正文 其他参考文献 无 ...