A. Déjà Vu

题意:就是问能否加上字母a,使得字符串不中心对称

思路:只有一种情况不能加入,就是全部是a,剩下的都可以满足,找a的位置就找哪个字母不是a,然后让它的对称位置是新加的这个a

代码:

 1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 using namespace std;
7 const int maxx=3e5+10;
8 int main(){
9 int t;
10 scanf("%d",&t);
11 while(t--){
12 char s[maxx];
13 scanf("%s",&s);
14 int n=strlen(s);
15 int a=0;
16 int flag=-1;
17 for(int i=0;i<n;i++){
18 if(s[i]!='a'){
19 flag=n-1-i;
20 }
21 }
22 if(flag==-1){
23 printf("NO\n");
24 }else{
25 printf("YES\n");
26 for(int i=0;i<n;i++){
27 if(i==flag){
28 printf("a");
29 }
30 printf("%c",s[i]);
31 }
32 printf("\n");
33 }
34 }
35 }

B. Flip the Bits

题意:通过前缀翻转,问a能不能变换为b字符串,并且保证前缀反转的字符串0和1的数量相等

思路:就是从后往前看,先用前缀和标记下来,可以反转的位置,然后从后往前看,能够反转的位置是相同还是相反,记录下来,因为再往左的下一次翻转中间的这些需要和开头的性质一样,然后一定注意是这次之前翻转了多少次,不算这次,也就是说这个值和看后面已经经历了多少个0不一样,会差1

代码:

  1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 using namespace std;
7 const int maxx=3e5+10;
8 int a[maxx]={0},b[maxx]={0},c[maxx]={0},ps[maxx]={0};
9 int main(){
10 int t;
11 scanf("%d",&t);
12 while(t--){
13 int n;
14 scanf("%d",&n);
15 int bb=0;
16 for(int i=0;i<n;i++){
17 scanf("%1d",&a[i]);
18 if(a[i]==0){
19 ps[i]=-1;
20 }else{
21 ps[i]=1;
22 }
23 }
24 for(int i=0;i<n;i++){
25 scanf("%1d",&b[i]);
26 }
27 int flag=0;
28 for(int i=0;i<n;i++){
29 if(i==0){
30 c[i]=ps[0];
31 }else{
32 c[i]=c[i-1]+ps[i];
33 }
34 //printf("i:%d ps:%d c:%d\n",i,ps[i],c[i]);
35 // printf("i:%d c:%d\n",i,c[i]);
36 }
37 int x=0,y=0;
38 /* for(int i=0;i<n;i++){
39 if(a[i]==0){
40 x++;
41 }else{
42 y++;
43 }
44 if(x==y){
45 c[i]=1;
46 }
47 }*/
48 /* for(int i=0;i<n;i++){
49 printf("%d",c[i]);
50 }
51 printf("\n");*/
52 int p=0;
53 flag=0;//1.��� 2.��ת
54 for(int i=n-1;i>=0;i--){//�ؼ��Ǵ���ǰ�ڴ�֮ǰ���й����ٴη�ת�������ǵ������֮ǰ���е���
55 //c�������0
56 if(c[i]==0){
57 bb++;
58 }
59 if(bb==0){
60 if(a[i]!=b[i]){
61 p=-1;
62 break;
63 }else{
64 continue;
65 }
66 }
67
68 if((bb-1)%2==0){
69 if(c[i]==0&&a[i]==b[i]){
70 flag=1;
71
72 }else if(c[i]==0&&a[i]!=b[i]){
73 flag=2;
74
75 }
76 if(c[i]!=0){
77 if(flag==0&&a[i]!=b[i]){
78 //printf("1: i:%d flag:%d bb:%d\n",i,flag,bb);
79 p=-1;
80 break;
81 }else if(flag==1&&a[i]!=b[i]){
82 // printf("2: i:%d flag:%d bb:%d\n",i,flag,bb);
83 p=-1;
84 break;
85 }else if(flag==2&&a[i]==b[i]){
86 // printf("3: i:%d flag:%d bb:%d\n",i,flag,bb);
87 p=-1;
88 break;
89 }
90 }
91 }else{
92 if(c[i]==0&&a[i]!=b[i]){
93 flag=1;
94
95 }else if(c[i]==0&&a[i]==b[i]){
96 flag=2;
97
98 }
99 if(c[i]!=0){
100 if(flag==0&&a[i]==b[i]){
101 //printf("4: i:%d flag:%d bb:%d\n",i,flag,bb);
102 p=-1;
103 break;
104 }else if(flag==1&&a[i]==b[i]){
105 //printf("5: i:%d flag:%d bb:%d\n",i,flag,bb);
106 p=-1;
107 break;
108 }else if(flag==2&&a[i]!=b[i]){
109 // printf("6: i:%d flag:%d bb:%d\n",i,flag,bb);
110 p=-1;
111 break;
112 }
113 }
114 }
115 // printf("i:%d b:%d\n",i,bb);
116 }
117 if(p==-1){
118 printf("NO\n");
119 }else{
120 printf("YES\n");
121 }
122 }
123 }

C. Balance the Bits

见https://www.bilibili.com/read/cv10616355

思考:1)就是大体就是1和0分开考虑,然后集合起来再思考总体需要满足的条件;2)1是相对于1的个数来说的,而0是相对于0的相对位置来说的;3)一定注意return0的位置

代码:

  1 #include<iostream>
2 #include<algorithm>
3 #include<cstring>
4 #include<cstdio>
5 #include<cmath>
6 using namespace std;
7 const int maxx=2e5+10;//一个是直接return 0了,一个就是全部是1的也是可以的
8 int main(){
9 int t;
10 scanf("%d",&t);
11 while(t--){
12 int n;
13 int a[maxx]={0};
14 scanf("%d",&n);
15 int sumx=0,sumy=0;
16 for(int i=0;i<n;i++){
17 scanf("%1d",&a[i]);
18 if(a[i]==0){
19 sumx++;
20 }else{
21 sumy++;
22 }
23 }
24 if(sumx%2==1){
25 printf("NO\n");
26 continue;
27 }
28 int x=1,y=0;//x.0的个数 y.1的个数
29 int b[maxx]={0};//0.you 1.z
30 for(int i=0;i<n;i++){
31 // printf("a[%d]:%d x:%d\n",i,a[i],x);
32 if(a[i]==1&&y<sumy/2){
33 b[i]=0;
34 y++;
35 }else if(a[i]==1&&y>=sumy/2){
36 b[i]=1;
37 // y++;
38 }
39 if(a[i]==0&&x%2==1){
40 b[i]=0;
41 x=0;
42 }else if(a[i]==0&&x%2==0){
43 b[i]=1;
44 x=1;
45 }
46 }
47 /* for(int i=0;i<n;i++){
48 printf("%d",b[i]);
49 }
50 printf("\n");*/
51
52 x=0;
53 y=0;
54 int f=0;
55 for(int i=0;i<n;i++){
56 if(b[i]==0){
57 x++;
58 }else{
59 y++;
60 }
61 if(x<y){
62 f=1;
63 }
64 }
65 if(x!=y||f==1){
66 printf("NO\n");
67 continue;
68 }
69 x=0;
70 y=0;
71 f=0;
72 for(int i=0;i<n;i++){
73 if(a[i]==0){
74 if(b[i]==0){
75 y++;
76 }else{
77 x++;
78 }
79 }else{
80 if(b[i]==0){
81 x++;
82 }else{
83 y++;
84 }
85 }
86 if(x<y){
87 f=1;
88 }
89 }
90 if(x!=y||f==1){
91 printf("NO\n");
92 continue;
93 }
94 printf("YES\n");
95 for(int i=0;i<n;i++){
96 if(b[i]==0){
97 printf("(");
98 }else{
99 printf(")");
100 }
101 }
102 printf("\n");
103 for(int i=0;i<n;i++){
104 if(a[i]==0){
105 if(b[i]==0){
106 printf(")");
107 }else{
108 printf("(");
109 }
110 }else{
111 if(b[i]==0){
112 printf("(");
113 }else{
114 printf(")");
115 }
116 }
117 }
118 printf("\n");
119 }
120 }

Codeforces Round #712 (Div. 2)的更多相关文章

  1. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  2. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  3. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  4. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  5. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

  6. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  7. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

  8. Codeforces Round #371 (Div. 1)

    A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...

  9. Codeforces Round #268 (Div. 2) ABCD

    CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...

随机推荐

  1. HTML标签解读

    因为最近在学习爬虫,那么在爬取网页内容时,就要求我们能够简单的看懂这个网页的基本结构,才能更好的去爬取我们所需要的内容. 这篇随笔也只是简单的说明了一些标签的含义. 标签关系 包含关系 eg:< ...

  2. effective解读-第一条 静态工厂创建对象代替构造器

    好处 有名称,能见名知意.例如BigInteger的probablePrime方法 享元模式.单例模式中使用 享元模式:创建对象代价很高,重复调用已有对象,例如数据库连接等.享元模式是单例模式的一个拓 ...

  3. C语言之动态内存管理

    C语言之动态内存管理 大纲: 储存器原理 为什么存在动态内存的开辟 malloc() free() calloc() realloc() 常见错误 例题 柔性数组 零(上).存储器原理 之前我们提到了 ...

  4. [矩阵乘法]裴波拉契数列III

    [ 矩 阵 乘 法 ] 裴 波 拉 契 数 列 I I I [矩阵乘法]裴波拉契数列III [矩阵乘法]裴波拉契数列III Description 求数列f[n]=f[n-1]+f[n-2]+1的第N ...

  5. Azure DevOps 跨账号连接 Azure 服务

    一,引言 由于新申请的 Azure DevOps 账号中的私有项目不在享受托管代理提供的1800分钟的免费时间,又不想花钱付费,那我们只能另想版本解决没有并行作业的问题. -------------- ...

  6. DevOps教程:DevOps 面试题

     [注]本文译自:https://www.javatpoint.com/devops-interview-questions

  7. 【算法学习笔记】组合数与 Lucas 定理

    卢卡斯定理是一个与组合数有关的数论定理,在算法竞赛中用于求组合数对某质数的模. 第一部分是博主的个人理解,第二部分为 Pecco 学长的介绍 第一部分 一般情况下,我们计算大组合数取模问题是用递推公式 ...

  8. inline&register

    inline关键字: 内联只是一个请求,不代表编译器会响应:同时某些编译器会将一些函数优化成为内联函数. C++在类内定义的函数默认是内联函数,具体是否真变成内联函数还需看编译器本身. registe ...

  9. Nginx/Apache + acme.sh 实现https访问

    1 概述 acme.sh实现了acme协议,可以从Let's Encrypt生成免费的ssl证书用于实现https,本文介绍了常见的两种服务器Apache与Nginx上利用acme.sh配置https ...

  10. JDBC_13_封装JDBC工具类

    封装JDBC工具类 代码: import java.sql.*; /** * JDBC工具类,简化JDBC编程 */ public class DBUtil { //工具类中的构造方法都是私有的,因为 ...