A
执行一次操作后字符串会编程镜像串,因此,答案只有1和2两种,分类讨论即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int mod=998244353;
const int N=200100;
int solve(){
int n,k;
cin>>n>>k;
string a,b;
cin>>a;
b=a;
reverse(b.begin(),b.end());
if(a==b){
return 1;
}
else if(k==0) return 1;
else return 2;
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){
cout<< solve()<<endl;
}
return 0;
}
B
由于奇偶性不同,只需要看个位的奇偶性即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int mod=998244353;
const int N=100100;
int a[N];
int solve(){
int n;
ll x,y;
cin>>n;
cin>>x>>y;
ll cnt=0;
for( int i=0;i<n;i++){
cin>>a[i];
cnt+=a[i]%2;
}
if(cnt%2==0){
if((x+y)%2==0) return 1;
else return 0;
}
else {
if((x+y)%2==0) return 0;
else return 1;
}
}
int main(){
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){
if(solve()) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
return 0;
}
C
构造等差数列即可
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int mod=998244353;
const int N=100100;
int a[N];
int solve(){
int n,k;
cin>>n>>k;
if(k==1){
cout<<"YES"<<endl;
for( int i=1;i<=n;i++) cout<<i<<endl;
return 0;
}
if(n%2==1||n==1){
cout<<"NO"<<endl;
}
else {
cout<<"YES"<<endl;
for( int i=1;i<=n;i++){
for( int j=i;j<=n*k;j+=n){
cout<<j<<" ";
}
cout<<endl;
}
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
D
四个元素为一组,迭代寻找
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define endl '\n'
const int mod=998244353;
const int N=200100;
int query(int i, int j, int k) {
cout << "? " << i + 1 << " " << j + 1 << " " << k + 1 << endl;
cout.flush();
int ans;
cin >> ans;
return ans;
}
int cal( int x,int y,int z){
return max(x,max(y,z))-min(x,min(y,z));
}
int cmp(pair<int,int>a,pair<int,int>b){
return a.first<b.first;
}
void solve(){
int n;
cin>>n;
vector<pair<int,int> >v(4);
int x=0,y=1;
for( int i=2;i<n;i+=2){
int p[4]={x,y,i,i};
if (i + 1 < n) {
p[3]=i+1;
} else {
int z = 0;
while (z == x || z == y) {
z++;
}
p[3]=z;
}
for( int j=0;j<4;j++){
v[j].second=j;
v[j].first=query(p[(j+1)%4],p[(j+2)%4],p[(j+3)%4]);
}
sort(v.begin(),v.end());
x=p[v[0].second];
y=p[v[1].second];
}
cout<<"! "<<x+1<<" "<<y+1<<endl;
}
int main(){
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
E
由于每行的元素个数和每个元素的总个数都是偶数,因此,只需两个元素为一组,进行深搜即可。
#include <bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define mk(x,y) make_pair(x,y)
const int N=200100;
vector<int>h[N];
string ans[N];
vector<int>v,vv;
vector<pair<int,int> >pos[N];
int cnt[N];
void solve(){
int n;
cin>>n;
for( int i=0;i<n;i++){
int m;
cin>>m;
for( int j=0;j<m;j++){
int x;
cin>>x;
h[i].push_back(x);
v.push_back(x);
ans[i].push_back('?');
}
}
vv=v;
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
vv[i]=lower_bound(v.begin(),v.end(),vv[i])-v.begin()+1;
}
int idx=0;
for( int i=0;i<n;i++){
for( int j=0;j<h[i].size();j++){
h[i][j]=vv[idx++];
pos[h[i][j]].push_back(mk(i,j));
}
}
for( int i=0;i<N;i++) {
if(pos[i].size()%2!=0) {
cout<<"NO"<<endl;
return ;
}
}
vector<int>curx(n),curv(N);
for( int i=0;i<n;i++){
int m=h[i].size();
for( int j=0;j<m;j++){
int x=i,y=j;
if(ans[x][y]!='?') continue;
while(1){
ans[x][y]='L';
while(ans[x][curx[x]]!='?') curx[x]++;
ans[x][curx[x]]='R';
int temp=h[x][curx[x]];
if(temp==h[i][j]) break;
while(ans[pos[temp][curv[temp]].first][pos[temp][curv[temp]].second]!='?'){
curv[temp]++;
}
x=pos[temp][curv[temp]].first;
y=pos[temp][curv[temp]].second;
}
}
}
cout << "YES\n";
for (int i = 0; i < n; i++) {
cout << ans[i] << "\n";
}
}
int main(){
solve();
return 0;
}
F
将原数组转换成斐波那契生成数组处理即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int inf=0x3f3f3f3f;
int P = 1000000007;
using i64 = long long;
// assume -P <= x < 2P
int norm(int x) {
if (x < 0) {
x += P;
}
if (x >= P) {
x -= P;
}
return x;
}
template<class T>
T power(T a, int b) {
T res = 1;
for (; b; b /= 2, a *= a) {
if (b % 2) {
res *= a;
}
}
return res;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() const {
return x;
}
Z operator-() const {
return Z(norm(P - x));
}
Z inv() const {
assert(x != 0);
return power(*this, P - 2);
}
Z &operator*=(const Z &rhs) {
x = ll(x) * rhs.x % P;
return *this;
}
Z &operator+=(const Z &rhs) {
x = norm(x + rhs.x);
return *this;
}
Z &operator-=(const Z &rhs) {
x = norm(x - rhs.x);
return *this;
}
Z &operator/=(const Z &rhs) {
return *this *= rhs.inv();
}
friend Z operator*(const Z &lhs, const Z &rhs) {
Z res = lhs;
res *= rhs;
return res;
}
friend Z operator+(const Z &lhs, const Z &rhs) {
Z res = lhs;
res += rhs;
return res;
}
friend Z operator-(const Z &lhs, const Z &rhs) {
Z res = lhs;
res -= rhs;
return res;
}
friend Z operator/(const Z &lhs, const Z &rhs) {
Z res = lhs;
res /= rhs;
return res;
}
};
void solve(){
int n,q;
cin>>n>>q>>P;
vector<int>a(n),b(n);
vector<Z>c(n),fib(n);
fib[0]=1,fib[1]=1;
for( int i=2;i<n;i++) fib[i]=fib[i-1]+fib[i-2];
for( int i=0;i<n;i++) cin>>a[i];
for( int i=0;i<n;i++) cin>>b[i];
for( int i=0;i<n;i++) {
c[i]=a[i]-b[i];
}
for( int i=n-1;i>1;i--){
c[i]-=c[i-1]+c[i-2];
//cout<<c[i].val()<<endl;
}
if(n>1) c[1]-=c[0];
// c[0]-=1;
int sum=0;
for( int i=0;i<n;i++) sum+=(c[i].val()!=0);
auto modify=[&](int pos,int x){
if(c[pos].val()) sum--;
c[pos]+=x;
if(c[pos].val()) sum++;
};
for( int i=0;i<q;i++){
string s;
int l,r;
cin>>s>>l>>r;
l--,r--;
if(s=="A") {
modify(l,1);
if (r + 1 < n) modify(r + 1,P- fib[r - l + 1].val());
if (r + 2 < n) modify(r + 2,P- fib[r - l ].val());
}
else{
modify(l,P-1);
if (r + 1 < n) modify(r + 1, fib[r - l + 1].val());
if (r + 2 < n) modify(r + 2, fib[r - l ].val());
}
if(sum==0) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
//cout.tie(NULL);
solve();
}