当前位置: 首页 > news >正文

Codeforces Round 770 (Div. 2)

比赛链接:Dashboard - Codeforces Round 770 (Div. 2) - Codeforces

A. Reverse and Concatenate

题意:

思路:

假设 s = "abba" 经过1次操作后 -> "abbaabba"

        s = "abcd" 经过一次操作后 -> "abcddcba" 或 "dcbaabcd" 

回文字符串经过一次操作后只会产生 1 种字符串

非回文字符串经过一次操作后会产生 2 种字符串 -> 产生的字符串均是回文字符串

若 s 是回文字符串 答案为1

     s 是非回文字符串 答案为 2

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ( x & -x )#define int long long
typedef long long ll;
typedef pair<int, int> pii;
int qmi(int a, int b, int mod)
{int res = 1;while (b){if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}
bool is_prime(int n)
{if (n < 2)return false;for (int i = 2; i <= n / i; i++){if (n % i == 0)return false;}return true;
}
void solve()
{int n , k;cin >> n >> k;string s; cin >> s;if( !k ) cout << 1 << endl;else{for( int i = 0 , j = n - 1 ; j >= i ; j-- , i++ ){if( s[i] != s[j] ){cout << 2 << endl;return;}}cout << 1 << endl;}
}
signed main()
{int tt = 1;cin >> tt;while (tt--)solve();return 0;
}

 B. Fortune Telling(好题)

题意:

思路:(考察 加法 和 异或的关系 )

初始数字 为 x 和 x + 3 -> 一个为奇数 ,另一个为偶数

公式 : a + b == a ^ b ( mod 2 ) -> 操作1和操作2在 mod 2 的前提下,是等价的

在二进制下 ,经过一系列的操作后,判断 操作后的数字 与 y 的奇偶

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ( x & -x )#define int long long
typedef long long ll;
typedef pair<int, int> pii;
int qmi(int a, int b, int mod)
{int res = 1;while (b){if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}
bool is_prime(int n)
{if (n < 2)return false;for (int i = 2; i <= n / i; i++){if (n % i == 0)return false;}return true;
}
void solve()
{int n , x , y; cin >> n >> x >> y;vector<int> a(n + 1);for( int i = 1 ; i <= n ; i++ ) cin >> a[i];int temp = x;for( int i = 1 ; i <= n ; i++ ) temp ^= a[i];// 如果 temp 为奇数 , y 为偶数       temp 为偶数, y 为奇数if( (( temp & 1 ) ^ ( y & 1 )) == 1 )puts("Bob"); else puts("Alice");
}
signed main()
{int tt = 1;cin >> tt;while (tt--)solve();return 0;
}

C. OKEA

题意:

 思路:

构造题:奇数一行 ,偶数一行

[ 1 , n * k ] 中 奇数与偶数 只能相差 0 或 1

当 k == 1时,直接输出

当 n 为奇数时 ,奇数相差 k 个 , 且此时 k > 1 ,所以这种情况是错的

当 n 为偶数时,输出即可

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ( x & -x )#define int long long
typedef long long ll;
typedef pair<int, int> pii;
int qmi(int a, int b, int mod)
{int res = 1;while (b){if (b & 1) res = res * a % mod;a = a * a % mod;b >>= 1;}return res;
}
bool is_prime(int n)
{if (n < 2)return false;for (int i = 2; i <= n / i; i++){if (n % i == 0)return false;}return true;
}
void solve()
{int n , k; cin >> n >> k;if( k == 1 ){puts("YES");for( int i = 1 ; i <= n ; i++) cout << i << endl;return;}if( n & 1 ){puts("NO"); return;}puts("YES");for( int i = 1 , cnt = 0 ; i <= n * k ; i += 2 ){cout << i << " ";cnt++;if( cnt == k ){cout << endl; cnt = 0;}}for( int i = 2 , cnt = 0 ; i <= n * k ; i += 2 ){cout << i << " ";cnt++;if( cnt == k ){cout << endl; cnt = 0;}}
}
signed main()
{int tt = 1;cin >> tt;while (tt--)solve();return 0;
}


http://www.mrgr.cn/news/51491.html

相关文章:

  • 一文教会你PyTorch 实现人脸识别
  • QT<28> Qt中对.ini配置文件的读写
  • 滚雪球学Redis[6.4讲]:Redis消息队列:构建高效的消息通信与任务调度系统
  • 2024软考网络工程师笔记 - 第3章.广域通信网
  • c++STL——map与set的使用及介绍
  • QT--Qlabel学习、获取文本和设置文本、文本对齐方式、文本换行、显示图片
  • 不坑盒子Office插件,2024年10月,全部功能列表
  • dlib库实现人脸检测
  • 【算法题解】二分查找的经典问题解析
  • SAP 第三方销售简介
  • 【C语言教程】【常用类库】(十四)可移植库 - <unistd.h> 和 <sys/types.h>
  • html转pdf 分页问题 包含自定义页头页尾
  • 5G NR:UE初始接入信令流程浅介
  • SQLServer-ASYNC_NETWORK_IO等待事件
  • 光伏项目开发360°管控,规避潜在风险
  • java 利用mpxj解析MPP及结合jacob导出MPP
  • 【图解版】力扣第146题:LRU缓存
  • 全国职业技能大赛——信息安全管理与评估第一阶段BC、FW、WAF题目详细解析过程
  • 安卓設備上怎麼設置HTTP代理?
  • apifox发送请求,参数类型为枚举类