标签:abs rect 16px i++ second std tin value 分享
A. Palindromic Twist
给一个字符串(小写字母) 每个字符+1,-1;变成其他字符 a只能变b z只能变y 看能否变成回文字符串
#include<bits/stdc++.h> using namespace std; int32_t main() { int T; cin>>T; while(T--) { int n; cin>>n; string ss; cin>>ss; int t=1; for(int i=0;i<n/2;i++) { if(ss[i]-ss[n-1-i]==0||fabs(ss[i]-ss[n-1-i])==2) continue; else t=0; } if(t==0) cout<<"NO"<<endl; else cout<<"YES"<<endl; } }
B. Numbers on the Chessboard
分类讨论下就ok了
#include<bits/stdc++.h> #define int long long #define MAX(a,b,c) max(a,max(b,c)) #define MIN(a,b,c) min(a,min(b,c)) #define pb push_back #define fi first #define se second typedef long long ll; typedef long long LL; typedef unsigned long long ull; typedef unsigned long long uLL; using namespace std; const int maxn=1e5+10; const int INF=0x3f3f3f3f; int32_t main() { int n,q; cin>>n>>q; if(n%2==0) { int ans1=0; int ans2=n*n/2; while(q--) { int a,b;cin>>a>>b; if( (a+b)%2==0 ) cout<<ans1+(a-1)*n/2+(b+1)/2<<endl; else cout<<ans2+(a-1)*n/2+(b+1)/2<<endl; } } else if(n%2==1) { int ans1=0; int ans2=n*n/2+1; while(q--) { int a,b;cin>>a>>b; if( (a+b)%2==0 ) { if(a%2==1) cout<<(a-1)/2*n+(b+1)/2<<endl; else if(a%2==0) cout<<(a-2)/2*n+(n+1)/2+(b+1)/2<<endl; } else { if(a%2==1) cout<<ans2+(a-1)/2*n+(b+1)/2<<endl; else if(a%2==0) cout<<ans2+(a-2)/2*n+(n-1)/2+(b+1)/2<<endl; } } } }
C. Minimum Value Rectangle
标签:abs rect 16px i++ second std tin value 分享
原文地址:https://www.cnblogs.com/Andromeda-Galaxy/p/9523140.html