当前位置: 首页 > 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.lryc.cn/news/461859.html

相关文章:

  • ProteinMPNN中蛋白质特征提取
  • Word中如何删除表格下一页的空白页
  • RabbitMQ 如何保证消息不丢失?
  • Oracle或者PL/SQL导入pde文件
  • 【QAMISRA】解决导入commands.json时报错问题
  • 影刀RPA实战番外:excel函数应用指南
  • php生成PDF文件(FPDF)
  • (接口测试)day01接口测试理论 http理论 接口测试流程 接口文档解析
  • Telegram——Bot 机器人/小程序入门指南
  • tauri build 后界面样式失效
  • 打印自然常数E
  • 澳鹏干货 | 大语言模型的上下文窗口 (Context Windows)
  • 为什么k8s不支持docker-kubernetes
  • 数据结构编程实践20讲(Python版)—17散列
  • 看了大厂用AI审简历,我才发现社会的残酷真相!今年的秋招太可怕了
  • 京东大模型革命电商搜推技术:挑战、实践与未来趋势
  • 深入学习二叉树(BinaryTree)(纯小白进)
  • 诗风秦韵诗词学习画廊宣言
  • Cannot determine local hostname
  • 电工课堂-对晶闸管移相控制触发要求
  • 基于Arduino做的“鱿鱼游戏”BOSS面具,支持动作检测
  • 数据库的查询操作
  • WebGL编程指南 - WebGL概述
  • 前端杂学录(十)
  • C++上机|编写函数invert实现对一维数组的倒序
  • 使用LSPatch+PlusNE修改手机软件
  • 基于springboot的4S店车辆管理系统
  • C++从入门到起飞之——(multi)set与(multi)map的的使用 全方位剖析!
  • HTML5实现古典音乐网站源码模板2
  • 基于SpringBoot+Vue+uniapp的诗词学习系统的详细设计和实现