A - ab (atcoder.jp)
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
int n;
string s;
void solve() {cin>>n>>s;for(int i=0;i<(int)s.size()-1;i++){if((s[i]=='a'&&s[i+1]=='b')||(s[i]=='b'&&s[i+1]=='a')){cout<<"Yes"<<endl;return;}}cout<<"No"<<endl;
}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;
// cin>>t;while(t--) {solve();}return 0;
}
B - A^A (atcoder.jp)
指数爆炸
通过打表发现大概16的16次方就已经越界了,然后15没有越界,所以只要枚举1的1次方,2的2次方,...15的15次方即可
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
using namespace std;
int x;
void solve() {cin>>x;for(int i=1;i<=15;i++){int ans=1;for(int j=1;j<=i;j++){ans*=i;}if(ans==x){cout<<i<<endl;return;}}cout<<-1<<endl;
}
signed main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;
// cin>>t;while(t--) {solve();}return 0;
}
C - Number Place (atcoder.jp)
暴力模拟
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
const int N=10;
int a[N][N];
int n;
void solve() {for(int i=1;i<=9;i++){for(int j=1;j<=9;j++){cin>>a[i][j];}}for(int i=1;i<=9;i++){set<int>s;for(int j=1;j<=9;j++){s.insert(a[i][j]);}if(s.size()!=9){cout<<"No"<<endl;return;}}for(int j=1;j<=9;j++){set<int>s;for(int i=1;i<=9;i++){s.insert(a[i][j]);}if(s.size()!=9){cout<<"No"<<endl;return;}}for(int i=1;i<=9;i+=3){//3*3方阵行的起始for(int j=1;j<=9;j+=3){//3*3方阵列的起始set<int>s;for(int p=i;p<i+3;p++){for(int q=j;q<j+3;q++){s.insert(a[p][q]);}}if(s.size()!=9){cout<<"No"<<endl;return;}}}cout<<"Yes"<<endl;
}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;
// cin>>t;while(t--) {solve();}return 0;
}
D - Good Tuple Problem (atcoder.jp)
染色法判定二分图
AC代码:
#include<bits/stdc++.h>
#define endl '\n'
//#define int long long
using namespace std;
const int N=2e5+10;
int a[N],b[N];
int color[N];
int n,m;
vector<vector<int>>e(N);
bool dfs(int u,int c){color[u]=c;for(auto v:e[u]){if(!color[v]){if(!dfs(v,3-c)) return false;}else if(color[v]==c) return false;}return true;
}
void solve() {cin>>n>>m;for(int i=1;i<=m;i++) cin>>a[i];for(int i=1;i<=m;i++) cin>>b[i];for(int i=1;i<=m;i++){e[a[i]].push_back(b[i]);e[b[i]].push_back(a[i]);}for(int i=1;i<=n;i++){if(!color[i]){if(!dfs(i,1)){cout<<"No"<<endl;return;}}}cout<<"Yes"<<endl;
}
int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int t=1;
// cin>>t;while(t--) {solve();}return 0;
}