Codeforces Round #712 (Div. 2)
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)的更多相关文章
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
- 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 ...
- 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 ...
- Codeforces Round #371 (Div. 1)
A: 题目大意: 在一个multiset中要求支持3种操作: 1.增加一个数 2.删去一个数 3.给出一个01序列,问multiset中有多少这样的数,把它的十进制表示中的奇数改成1,偶数改成0后和给 ...
- Codeforces Round #268 (Div. 2) ABCD
CF469 Codeforces Round #268 (Div. 2) http://codeforces.com/contest/469 开学了,时间少,水题就不写题解了,不水的题也不写这么详细了 ...
随机推荐
- Java 给PPT添加动画效果(预设动画/自定义动画)
PPT幻灯片中对形状可设置动画效果,常见的动画效果为内置的固定类型,即动画效果和路径是预先设定好的固定模板,但在设计动画效果时,用户也可以按照自己的喜好自定义动画动作路径.下面,通过Java后端程序代 ...
- 通过《第一行代码》学习 Android 开发
第一行代码 Android --第 2 版-- 郭霖 著 第 1 章:开始启程--你的第一行 Android 代码 •1.2 手把手带你搭建开发环境 Android Studio 的安装及配置 A ...
- 《环形队列》游戏高《TPS》模式下减少cpu线程切换
序言 什么高TPS?QPS,其实很多人都知道,还有人说大数据,大流量这些关键词夜以继日的出现在我们眼前: 针对高TPS,QPS这些词汇还有一个次可能比较陌生那就是CCU,tps,qps接受满天飞,CC ...
- java面试-生产环境出现CPU占用过高,谈谈你的分析思路和定位
思路:结合Linux和JDK命令一起分析 1.用top命令找出CPU占比最高的进程 2.ps -ef|grep java|grep -v grep 或者jps -l进一步定位,得知是怎样一个后台程序惹 ...
- leetcode 783 二叉搜索树节点最小距离
PS:(感觉这题名字和内容有歧义) 要求得到任意不同节点值之间的最小差值. 本身二叉树是有序的,又找最小差值,其实就是相当于在一个有序数组中找到每相邻两数之间最小差值. 朴素思想: 中序遍历树,把值都 ...
- OO_Unit1_Summary
经历了十分充实(痛不欲生)的三周不一样的码代码的生活,让我对通宵oo有了新的认识.往届学长学姐诚不欺我 第一次作业 需求分析 第一次需求非常简单(相比较后两次作业而言),仅为简单多项式求导,而且仅包含 ...
- 如何在IDEA中进行时序图分析
方法一: 使用插件 SequenceDiagram (系统自动生成) 使用方法: 下载插件,我们可以在 Plugins 中找到 选中线程方法名,然后右键就可以创建此方法的时序图了 参数设置 生成效果以 ...
- ES系列(二):基于多播的集群发现实现原理解析
ES作用超强悍的搜索引擎,除了需要具有齐全的功能支持,超高的性能,还必须要有任意扩展的能力.一定程度上,它是一个大数据产品.而要做扩展性,集群自然少不了.然而单独的集群又是不够的,能够做的事情太少,所 ...
- 【笔记】《Redis设计与实现》chapter21 排序
chapter21 排序 21.1 SORT<key> 命令的实现 // 用于保存被排序值及其权重的结构 typedef struct _redisSortObject { // 被排序键 ...
- Pycharm Fiddler Requests https in _create raise ValueError("check_hostname requires server_hostname
打开Fiddler, 开启抓取https, 在PyCharm中使用requests 发送https请求, 遇到 in _create raise ValueError("check_ho ...