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. 信息论-Turbo码学习

    1.Turbo码: 信道编码的初期:分组码实现编码,缺点有二:只有当码字全部接收才可以开始译码,需要精确的帧同步时延大,增益损失多 解决方案:卷积码:充分利用前一时刻和后一时刻的码组,延时小,缺点:计 ...

  2. CSS 背景常用属性

    CSS 背景常用属性 background-color 这个属性过于简单, 以下写法均可 background-color:red; background-color:rgb(0,0,255); ba ...

  3. K尾相等数(模运算)

    Description 从键盘输入一个自然数K(K>1),若存在自然数M和N(M>N),使得K^M^和K^N^均大于或等于1000,且他们的末尾三位数相等,则称M和N是一对"K尾 ...

  4. 03、MyBatis 映射文件

    1.XML映射器 2.select Select元素来定义查询操作 Id:唯一标识符 - 用来引用这条语句,需要和接口的方法名一致 parameterType:参数类型 - 可以不传,MyBatis会 ...

  5. msfvenom制作payload

    windows msfvenom -a x86 --platform Windows -p windows/meterpreter/reverse_tcp LHOST=攻击机IP LPORT=攻击机端 ...

  6. 思维导图iMindMap可以在哪些领域应用

    生活工作中你常常会遇到许多力所不能及的事情,感到无奈.茫然,这时候你急需一个帮手来帮你打破困境,思维导图就是这样的救世主,至于它有哪些力所能及的事情就是下面小编要跟你讲的. 你是否经常遇到过这样的情况 ...

  7. FL Studio音频混音教程

    FL Studio是一款音乐制作.编曲.混音软件,其内置众多电子合成音色,还支持第三方VST等格式插件.软件操作界面简洁易上手,即使你是零音乐基础小白,通过它也能轻松实现自己音乐梦想,很多人给他起了个 ...

  8. 使用QQ登陆

    到这里https://connect.qq.com,申请成为开发者,然后等着审核通过 通过了,创建网站应用,回调地址必须是备案成功的网站上的,然后等着审核通过 通过了,得到正确的appid和appke ...

  9. centos7 ping: baidu.com: Name or service not known

    虚拟机 centos7配置ip后 ping 网关可以ping 通,但是ping不通外网 baidu.com 报错为: ping: baidu.com: Name or service not know ...

  10. yii2 删除数据

    直接 model 删除 $model = User::find($id); $model->delete(); 带有条件的删除 $connection ->createCommand() ...