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. jboss反序列化漏洞实战渗透笔记

    一.利用shodan,fofa或谷歌搜索关键字:8080/jmx-console/ 二.下载java反序列化终极测试工具进行验证漏洞 三.记住User Current Directory:  C:\j ...

  2. 使用Folx智能速控功能,确保带宽资源的合理分配

    市面上的大部分下载软件,都会配备速度控制的功能,用于限制下载任务的带宽占用.但除此之外,Folx专业版还提供了更加智能化的速度控制功能,用户可以为速控指定更加详细的条件,比如程序限制条件.时间限制条件 ...

  3. 巧妙运用Camtasia 旅行Vlog轻松get

    旅行时,除了要欣赏当地的美丽风景.享受当地美食外,当然还要将旅行中的各种小细节记录下来.以前我们可能更多地使用相机拍照,现在呢,越来越多的人采用视频拍摄的方式制作Vlog.这种兼具影像与叙事的视频表现 ...

  4. java中String类的使用

    一.Strng类的概念 String类在我们开发中经常使用,在jdk1.8版本之前(包括1.8),String类的底层是一个char类型的数组,1.8版本之后是byte类型的数组,正是因为String ...

  5. 解决-Chrome插件安装时程序包无效:"CRX_HEADER_INVALID"

    最近安装新的谷歌插件出现 :程序包无效:"CRX_HEADER_INVALID" 原因如下: 在地址栏输入chrome://settings/help 如果,你的 Chrome 浏 ...

  6. 【Luogu U41492】树上数颜色——树上启发式合并(dsu on tree)

    (这题在洛谷主站居然搜不到--还是在百度上偶然看到的) 题目描述 给一棵根为1的树,每次询问子树颜色种类数 输入输出格式 输入格式: 第一行一个整数n,表示树的结点数 接下来n-1行,每行一条边 接下 ...

  7. Matlab 画图2

    fplot函数 plot函数的缺点:在实际应用中,函数随着自变量的变化趋势是未知的,如果自变量的离散区间不合理,则无法反应函数的变化趋势. fplot的作用:通过自适应算法,解决上述问题. fplot ...

  8. Forethought Future Cup - Final Round (Onsite Finalists Only) C. Thanos Nim 题解(博弈+思维)

    题目链接 题目大意 给你n堆石子(n为偶数),两个人玩游戏,每次选取n/2堆不为0的石子,然后从这n/2堆石子中丢掉一些石子(每一堆丢弃的石子数量可以不一样,但不能为0),若这次操作中没有n/2堆不为 ...

  9. Java基础教程——封装

    面向对象的三大特征 封装:encapsulation 继承:inheritance 多态:polymorphism 封装 类是一个最基本的封装 封装的好处: 数据安全:保证数据安全 方便调用:提供清晰 ...

  10. 数据库default null字段用基本类型映射,改成包装类型后缓存中旧数据反序列化失败

    rt,spring Temp不知道用的什么反序列化,int不能反序列化为Integer,后实验hissing是可以的int->Integer  Integer(不为null)->int均可