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. Line-line Intersection Gym - 102220C

    题目链接:https://vjudge.net/problem/Gym-102220C 题意:求n 条直线两两相交有几对(也可以重合). 思路:用map和pair存所有直线的斜率和与X轴的交点,假设与 ...

  2. 攻防世界 reverse 进阶 9-re1-100

    9.re1-100 1 if ( numRead ) 2 { 3 if ( childCheckDebugResult() ) 4 { 5 responseFalse(); 6 } 7 else if ...

  3. HTTPS证书通过cert-manager自动获取,部署,续期

    HTTP-01验证和DNS-01验证 使用cert-manager给阿里云的DNS域名授权SSL证书 第一步:安装cert-manager 配置 CRD kubectl apply -f https: ...

  4. ELK查询命令详解总结

    目录 ELK查询命令详解 倒排索引 倒排索引原理 分词器介绍及内置分词器 使用ElasticSearch API 实现CRUD 批量获取文档 使用Bulk API 实现批量操作 版本控制 什么是Map ...

  5. 微信小程序getUserProfile适配方案

    清明节放假前一天 群里突然炸锅,说小程序所有用的昵称全部变成了微信昵称 当时我就 特么不是说好13号吗??? 吓得我赶紧爬起来翻文档(需要代码直接往后翻) wx.getUserProfile(Obje ...

  6. [图论]最优布线问题:prim

    最优布线问题 目录 最优布线问题 Description Input Output Sample Input Sample Output Hint 解析 代码 Description 学校有n台计算机 ...

  7. [贪心]P1049 装箱问题

    装箱问题 题目描述 有一个箱子容量为V(正整数,0≤V≤20000),同时有n个物品(0<n≤30),每个物品有一个体积(正整数). 要求n个物品中,任取若干个装入箱内,使箱子的剩余空间为最小. ...

  8. ES9的新特性:异步遍历Async iteration

    ES9的新特性:异步遍历Async iteration 目录 简介 异步遍历 异步iterable的遍历 异步iterable的生成 异步方法和异步生成器 简介 在ES6中,引入了同步iteratio ...

  9. OO第一单元作业——魔幻求导

    简介 本单元作业分为三次 第一次作业:需要完成的任务为简单多项式导函数的求解. 第二次作业:需要完成的任务为包含简单幂函数和简单正余弦函数的导函数的求解. 第三次作业:需要完成的任务为包含简单幂函数和 ...

  10. 数据结构☞二叉搜索树BST

    二叉查找树(Binary Search Tree),(又:二叉搜索树,二叉排序树)它可以是一棵空树,也可以是具有下列性质的二叉树: 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值: 若它 ...