欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > Codeforces Round 770 (Div. 2)

Codeforces Round 770 (Div. 2)

2024/10/23 15:30:59 来源:https://blog.csdn.net/wx20041102/article/details/142989633  浏览:    关键词: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;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com